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, HTTP]

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

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

Acronym of current protocol.

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

Version of current protocol.

classmethod id()[source]

Index ID of the protocol.

Return type:

tuple[Literal['HTTP'], Literal['HTTPv1']]

Returns:

Index ID of the protocol.

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(http_version='1.1', method=None, uri=None, status=None, status_default=None, status_namespace=None, status_reversed=False, message=None, headers=None, body=b'', **kwargs)[source]

Make (construct) packet data.

Parameters:
Return type:

HTTP

Returns:

Constructed packet data.

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (HTTP) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

_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.

Return type:

tuple[Header, OrderedMultiDict[str, str]]

Returns:

Parsed packet data.

Raises:

ProtocolError – If the packet is malformed.

_read_http_body(body, *, headers)[source]

Read HTTP/1.* body.

Parameters:
Return type:

Any

Returns:

Raw HTTP body.

Auxiliary Data

class pcapkit.protocols.application.httpv1.Type(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: StrEnum

HTTP packet type.

REQUEST = 'request'

Request packet.

RESPONSE = 'response'

Response packet.

static _generate_next_value_(name, start, count, last_values)

Return the lower-cased version of the member name.

Header Schemas

class pcapkit.protocols.schema.application.httpv1.HTTP(dict_=None, **kwargs)[source]

Bases: Schema

Header schema for HTTP/1.* packet.

data: bytes = <BytesField data>

Packet data.

Data Models

class pcapkit.protocols.data.application.httpv1.HTTP(*args: VT, **kwargs: VT)[source]

Bases: Protocol

Data model for HTTP/1.* protocol.

receipt: Header

HTTP receipt.

header: OrderedMultiDict[str, str]

HTTP header.

body: Any

HTTP body.

class pcapkit.protocols.data.application.httpv1.Header(dict_=None, **kwargs)[source]

Bases: Data

Data model for HTTP/1.* header line.

type: HTTP_Type

Receipt type.

class pcapkit.protocols.data.application.httpv1.RequestHeader(*args: VT, **kwargs: VT)[source]

Bases: Header

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

type: HTTP_Type

HTTP request header line.

method: Enum_Method

HTTP method.

uri: str

HTTP request URI.

version: str

HTTP request version.

class pcapkit.protocols.data.application.httpv1.ResponseHeader(*args: VT, **kwargs: VT)[source]

Bases: Header

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

type: HTTP_Type

HTTP response header line.

version: str

HTTP response version.

status: Enum_StatusCode

HTTP response status.

message: str

HTTP response status message.

Footnotes