HTTP/1.* - Hypertext Transfer Protocol¶
Removed in version 1.6.0: pcapkit.protocols.application.httpv1.Type, with no alias: it is in this module,
and pcapkit.protocols.application.httpv1 exports the protocol class alone
(#2534).
pcapkit.protocols.application.httpv1.protocol contains
HTTPv1,
which implements an extractor for Hypertext Transfer
Protocol (HTTP/1.*) [*], and its
Type enumeration. The
structure of an HTTP/1.* message is:
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)
Changed in version 1.5.0: A message rebuilds byte for byte: the whitespace of the start line and header lines, and octets in them that are not UTF-8, are kept as captured rather than normalised or re-encoded (#1241, #1302, #1333).
Removed in version 1.6.0: pcapkit.protocols.application.httpv1.HTTP, with no alias. The
class is renamed HTTPv1,
after its module (#2529).
- class pcapkit.protocols.application.httpv1.protocol.HTTPv1(file=None, length=None, **kwargs)[source]¶
-
This class implements Hypertext Transfer Protocol (HTTP/1.*).
Changed in version 1.6.0:
statusofmake()takes aStatusCodemember or anintcode, resolved with itsget, so a code given with nomessagewrites its member’s message, as the member does; a name, abool, or a code past999raisesProtocolError, rather than resolving against the enumeration or writing more than three digits (#2594).Removed in version 1.6.0: The
status_default,status_namespaceandstatus_reversedarguments ofmake(); resolve a name withresolve_index()first (#2594).- 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:
- Return type:
- Returns:
Parsed packet data.
- Raises:
ProtocolError – If the packet is malformed.
- make(http_version='1.1', method=None, uri=None, status=None, message=None, headers=None, body=b'', charset=None, raw_line=None, raw_header=(), **kwargs)[source]¶
Make (construct) packet data.
The start line and the field lines are built from the parsed values with single SPs,
name: valueand UTF-8 field values.raw_lineis written in place of the start line, and eachraw_headerentry in place of the header field at the same position, whenever reading it back gives the same values – so a message rebuilds byte for byte, whitespace,obs-foldand field-value charset included, while a value that has been changed is written from the change. Field lines are matched toheadersby content and in order, so adding or removing a field leaves the others as received.- Parameters:
http_version (
Literal['0.9','1.0','1.1',b'0.9',b'1.0',b'1.1']) – HTTP version.status (
StatusCode|int|None) – HTTP status code.message (
str|bytes|None) – HTTP status message; if not given, the messageStatusCodegivesstatus.headers (
OrderedMultiDict[str,str] |None) – HTTP headers.body (
bytes) – HTTP body.charset (
str|None) – Encoding for astrrequest URI or status message, UTF-8 if not given.raw_line (
bytes|None) – HTTP start line as received, CRLF excluded.raw_header (
Sequence[bytes]) – HTTP field lines as received, CRLF excluded, one per header field and in the order ofheaders.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- Raises:
ProtocolError – If the values are neither a request’s nor a response’s, if they are a request’s and
uriisNone, or ifraw_lineor araw_headerentry that reads back as the given values carries a CR or LF that the values do not (other than the CRLF of anobs-fold), or ifstatusis a name, abool, or a member or code that is not three decimal digits.
- classmethod id()[source]¶
Index ID of the protocol.
RFC 9112 names the protocol
HTTP/1.1. This class also reads messages declaring HTTP/1.0 or HTTP/0.9, so its name carries the major version alone, andaliasthe exact one.Changed in version 1.6.0:
('HTTP/1',), narrowed to this class, where it was('HTTP', 'HTTPv1')(#2524).
- _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:
- Returns:
Parsed packet data.
- Raises:
ProtocolError – If the packet is malformed.
Auxiliary Data¶
- class pcapkit.protocols.application.httpv1.protocol.Type(*values)[source]¶
Bases:
EnumLookup,StrEnumHTTP packet type.
Built on
EnumLookup, the lookup contract shared by every non-registry enumeration (#877). The class defines neithergetnor_missing_of its own.- REQUEST = 'request'¶
Request packet.
- RESPONSE = 'response'¶
Response packet.
Header Schemas¶
Removed in version 1.6.0: pcapkit.protocols.schema.application.httpv1, with no alias: the module moved here
(#2534).
Data Models¶
Removed in version 1.6.0: pcapkit.protocols.data.application.httpv1, with no alias: the module moved here
(#2534).
Removed in version 1.6.0: pcapkit.protocols.data.application.httpv1.HTTP, with no alias. The
class is renamed HTTPv1,
after its module (#2529).
- class pcapkit.protocols.application.httpv1.data.HTTPv1(receipt, header, body, raw_header)[source]¶
Bases:
ProtocolData model for HTTP/1.* protocol.
- header: OrderedMultiInfo[str, str]¶
HTTP header.
- class pcapkit.protocols.application.httpv1.data.Header(*args, **kwargs)[source]¶
Bases:
DataData model for HTTP/1.* header line.
- class pcapkit.protocols.application.httpv1.data.RequestHeader(type, method, uri, version, charset, raw_line)[source]¶
Bases:
HeaderData model for HTTP/1.* request header line.
- class pcapkit.protocols.application.httpv1.data.ResponseHeader(type, version, status, message, charset, raw_line)[source]¶
Bases:
HeaderData model for HTTP/1.* response header line.
- status: StatusCode¶
HTTP response status.
Footnotes