HTTP - Hypertext Transfer Protocol

pcapkit.protocols.application.http contains HTTP only, which is a base class for Hypertext Transfer Protocol (HTTP) [*] family, eg. HTTP/1.* and HTTP/2.

class pcapkit.protocols.application.http.HTTP(file=None, length=None, **kwargs)[source]

Bases: Application[_PT, _ST], Generic[_PT, _ST]

This class implements all protocols in HTTP family.

  • Hypertext Transfer Protocol (HTTP/1.1) [RFC 7230]

  • Hypertext Transfer Protocol version 2 (HTTP/2) [RFC 7540]

property name: Literal['Hypertext Transfer Protocol']

Name of current protocol.

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

Acronym of current protocol.

property length: int

Header length of current protocol.

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

Version of current protocol.

classmethod id()[source]

Index ID of the protocol.

Return type:

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

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

Read (parse) packet data.

Parameters:
  • length (Optional[int]) – Length of packet data.

  • version (Optional[Literal[1, 2]]) – Version of HTTP.

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

Return type:

TypeVar(_PT, bound= Data)

Returns:

Parsed packet data.

make(version=1, **kwargs)[source]

Make (construct) packet data.

Parameters:
  • version (Literal[1, 2]) – Version of HTTP.

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

Returns:

Constructed packet data.

Return type:

bytes

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (TypeVar(_PT, bound= Data)) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

_guess_version(length, **kwargs)[source]

Guess HTTP version.

Parameters:

length (int) – Length of packet data.

Keyword Arguments:

**kwargs – Arbitrary keyword arguments.

Return type:

HTTP

Returns:

Parsed packet data.

Footnotes