HTTP/1.* - Hypertext Transfer Protocol¶
pcapkit.protocols.application.httpv1 contains
HTTP,
which implements extractor for Hypertext Transfer
Protocol (HTTP/1.*) [*], and its
Type enumeration. The
structure of an HTTP/1.* message 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)
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).
- class pcapkit.protocols.application.httpv1.HTTP(file=None, length=None, **kwargs)[source]¶
-
This class implements Hypertext Transfer Protocol (HTTP/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:
- Return type:
- 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'', 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|str|bytes|int|None) – HTTP status code.status_namespace (
dict[str,int] |dict[int,str] |Type[IntEnum] |Type[IntEnum] |None) – Namespace of HTTP status code.status_reversed (
bool) – Whether to reverse the namespace.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, or if
raw_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).
- _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.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.
- static _generate_next_value_(name, start, count, last_values)¶
Return the lower-cased version of the member name.
Header Schemas¶
Data Models¶
- class pcapkit.protocols.data.application.httpv1.HTTP(*args: VT, **kwargs: VT)[source]¶
Bases:
ProtocolData model for HTTP/1.* protocol.
- header: OrderedMultiInfo[str, str]¶
HTTP header.
- class pcapkit.protocols.data.application.httpv1.Header(dict_=None, **kwargs)[source]¶
Bases:
DataData model for HTTP/1.* header line.
- class pcapkit.protocols.data.application.httpv1.RequestHeader(*args: VT, **kwargs: VT)[source]¶
Bases:
HeaderData model for HTTP/1.* request header line.
- class pcapkit.protocols.data.application.httpv1.ResponseHeader(*args: VT, **kwargs: VT)[source]¶
Bases:
HeaderData model for HTTP/1.* response header line.
- status: StatusCode¶
HTTP response status.
Footnotes