HTTP/1.* - Hypertext Transfer Protocol

pcapkit.protocols.application.httpv1 contains HTTP only, which implements extractor for Hypertext Transfer Protocol (HTTP/1.*) *, whose structure is described as below:

METHOD URL HTTP/VERSION\r\n :==: REQUEST LINE
<key> : <value>\r\n         :==: REQUEST HEADER
............  (Ellipsis)    :==: REQUEST HEADER
\r\n                        :==: REQUEST SEPARATOR
<body>                      :==: REQUEST BODY (optional)

HTTP/VERSION CODE DESP \r\n :==: RESPONSE LINE
<key> : <value>\r\n         :==: RESPONSE HEADER
............  (Ellipsis)    :==: RESPONSE HEADER
\r\n                        :==: RESPONSE SEPARATOR
<body>                      :==: RESPONSE BODY (optional)
class pcapkit.protocols.application.httpv1.HTTP(file=None, length=None, **kwargs)[source]

Bases: HTTP[HTTP]

This class implements Hypertext Transfer Protocol (HTTP/1.*).

Parameters
  • *args (Any) – Arbitrary positional arguments.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type

Protocol[PT]

property alias: Literal['HTTP/0.9', 'HTTP/1.0', 'HTTP/1.1']

Acronym of current protocol.

Return type

Literal[‘HTTP/0.9’, ‘HTTP/1.0’, ‘HTTP/1.1’]

property version: Literal['0.9', '1.0', '1.1']

Version of current protocol.

Return type

Literal[‘0.9’, ‘1.0’, ‘1.1’]

read(length=None, **kwargs)[source]

Read Hypertext Transfer Protocol (HTTP/1.*).

Structure of HTTP/1.* packet [RFC 7230]:

HTTP-message    :==:    start-line
                        *( header-field CRLF )
                        CRLF
                        [ message-body ]
Parameters
  • length (Optional[int]) – Length of packet data.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type

HTTP

Returns

Parsed packet data.

Raises

ProtocolError – If the packet is malformed.

make(**kwargs)[source]

Make (construct) packet data.

Parameters

**kwargs (Any) – Arbitrary keyword arguments.

Return type

NoReturn

Returns

Constructed packet data.

classmethod id()[source]

Index ID of the protocol.

Returns

Index ID of the protocol.

Return type

tuple[Literal[“HTTP”]]

_read_http_header(header)[source]

Read HTTP/1.* header.

Structure of HTTP/1.* header [RFC 7230]:

start-line      :==:    request-line / status-line
request-line    :==:    method SP request-target SP HTTP-version CRLF
status-line     :==:    HTTP-version SP status-code SP reason-phrase CRLF
header-field    :==:    field-name ":" OWS field-value OWS
Parameters

header (bytes) – HTTP header data.

Returns

Parsed packet data.

Raises

ProtocolError – If the packet is malformed.

Return type

tuple[DataType_Header, OrderedMultiDict[str, str]]

_read_http_body(body)[source]

Read HTTP/1.* body.

Parameters

body (bytes) – HTTP body data.

Return type

bytes

Returns

Raw HTTP body.

pcapkit.protocols.application.httpv1.HTTP_METHODS = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE', 'OPTIONS', 'CONNECT', 'PATCH']

Supported HTTP method.

Data Structures

class pcapkit.protocols.data.application.httpv1.HTTP(receipt, header, body)[source]

Bases: HTTP

Data model for HTTP/1.* protocol.

Parameters
  • *args (VT) – Arbitrary positional arguments.

  • **kwargs (VT) – Arbitrary keyword arguments.

Return type

Info

receipt: Header

HTTP receipt.

header: OrderedMultiDict[str, str]

HTTP header.

body: Optional[bytes]

HTTP body.

class pcapkit.protocols.data.application.httpv1.Header(type)[source]

Bases: Info

Data model for HTTP/1.* header line.

Parameters
  • *args (VT) – Arbitrary positional arguments.

  • **kwargs (VT) – Arbitrary keyword arguments.

Return type

Info

type: Literal['request', 'response']

Receipt type.

class pcapkit.protocols.data.application.httpv1.RequestHeader(type, method, uri, version)[source]

Bases: Header

Data model for HTTP/1.* request header line.

Parameters
  • *args (VT) – Arbitrary positional arguments.

  • **kwargs (VT) – Arbitrary keyword arguments.

Return type

Info

type: Literal['request']

HTTP request header line.

method: str

HTTP method.

uri: str

HTTP request URI.

version: str

HTTP request version.

class pcapkit.protocols.data.application.httpv1.ResponseHeader(type, version, status, message)[source]

Bases: Header

Data model for HTTP/1.* response header line.

Parameters
  • *args (VT) – Arbitrary positional arguments.

  • **kwargs (VT) – Arbitrary keyword arguments.

Return type

Info

type: Literal['response']

HTTP response header line.

version: str

HTTP response version.

status: int

HTTP response status.

message: str

HTTP response status message.


*

https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol