HTTP/1.* - Hypertext Transfer Protocol

pcapkit.protocols.application.httpv1 contains HTTPv1 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.HTTPv1(file=None, length=None, **kwargs)[source]

Bases: pcapkit.protocols.application.http.HTTP

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

_read_http_body(body)[source]

Read HTTP/1.* body.

Parameters

body (bytes) – HTTP body data.

Returns

Raw HTTP body.

Return type

str

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

Return type

Union[DataType_HTTP_Request_Header, DataType_HTTP_Response_Header]

Raises

ProtocolError – If the packet is malformed.

classmethod id()[source]

Index ID of the protocol.

Returns

Index ID of the protocol.

Return type

Literal[‘HTTPv1’]

make(**kwargs)[source]

Make (construct) packet data.

Keyword Arguments

**kwargs – Arbitrary keyword arguments.

Returns

Constructed packet data.

Return type

bytes

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.

Keyword Arguments

**kwargs – Arbitrary keyword arguments.

Returns

Parsed packet data.

Return type

DataType_HTTP

Raises

ProtocolError – If the packet is malformed.

_receipt = None

Type of HTTP receipt.

Type

Literal[‘request’, ‘response’]

property alias

Acronym of current protocol.

Return type

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

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

Supported HTTP method.

pcapkit.protocols.application.httpv1._RE_METHOD = re.compile(b'GET|HEAD|POST|PUT|DELETE|TRACE|OPTIONS|CONNECT|PATCH')

Regular expression to match HTTP methods.

pcapkit.protocols.application.httpv1._RE_STATUS = re.compile(b'\\d{3}')

Regular expression to match HTTP status code.

pcapkit.protocols.application.httpv1._RE_VERSION = re.compile(b'HTTP/(?P<version>\\d\\.\\d)')

Regular expression to match HTTP version string.

Data Structure

Important

Following classes are only for documentation purpose. They do NOT exist in the pcapkit module.

class pcapkit.protocols.application.httpv1.DataType_HTTP
Bases

TypedDict

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

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

HTTP packet receipt.

header: Union[DataType_HTTP_Request_Header, DataType_HTTP_Response_Header]

Parsed HTTP header data.

body: bytes

HTTP body data.

raw: DataType_HTTP_Raw

Raw HTTP packet data.

class pcapkit.protocols.application.httpv1.DataType_HTTP_Raw
Bases

TypedDict

Raw HTTP packet data.

header: bytes

Raw HTTP header data.

body: bytes

Raw HTTP body data.

packet: bytes

Raw HTTP packet data.

class pcapkit.protocols.application.httpv1.DataType_HTTP_Request_Header
Bases

TypedDict

HTTP request header.

request: DataType_HTTP_Request_Header_Meta

Request metadata.

class pcapkit.protocols.application.httpv1.DataType_HTTP_Response_Header
Bases

TypedDict

HTTP response header.

response: DataType_HTTP_Response_Header_Meta

Response metadata.

class pcapkit.protocols.application.httpv1.DataType_HTTP_Request_Header_Meta
Bases

TypedDict

Request metadata.

method: str

HTTP request method.

target: str

HTTP request target URI.

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

HTTP version string.

class pcapkit.protocols.application.httpv1.DataType_HTTP_Response_Header_Meta
Bases

TypedDict

Response metadata.

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

HTTP version string.

status: int

HTTP response status code.

phrase: str

HTTP response status reason.


*

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