HTTP/2 - Hypertext Transfer Protocol

pcapkit.protocols.application.httpv2.protocol contains HTTPv2 only, which implements an extractor for Hypertext Transfer Protocol (HTTP/2) [*], whose structure is:

Octets

Bits

Name

Description

0

0

http.length

Payload Length

3

24

http.type

Type

4

32

http.flags

Flags

5

40

Reserved

5

41

http.sid

Stream Identifier

9

72

http.payload

Frame Payload

Frames in One Segment

A whole frame after the first in a TCP segment is dissected as a further HTTPv2 layer, the previous frame’s payload (#2536), as TLS chains records: a SETTINGS frame followed by a WINDOW_UPDATE reads TCP:HTTP/2:HTTP/2. The exceptions:

  • A whole frame that fails to decode becomes Raw together with everything after it, with the parser’s error.

  • A frame the segment ends inside, its header or its payload cut short, stays raw, with no error.

  • A parse told to stop at HTTP/2 (protocol='HTTP/2' or layer='Application') keeps the rest of the segment raw.

  • Each frame is a layer, so FRAME_LAYER_LIMIT bounds how many are dissected.

Changed in version 1.5.0: A frame’s Length counts its payload alone, not the 9-octet frame header, as RFC 9113 Section 4.1 defines it, and the payload is read to that Length rather than to the end of the buffer (#1121, #1243). A frame rebuilds byte for byte: END_STREAM, undefined flag bits, the reserved bits, a zero Pad Length, duplicate SETTINGS entries and the payload of an unpadded DATA, HEADERS or PUSH_PROMISE frame are kept (#652, #668, #1244, #1245, #1246, #1247).

Removed in version 1.6.0: pcapkit.protocols.application.httpv2.HTTP, with no alias. The class is renamed HTTPv2, after its module (#2529).


class pcapkit.protocols.application.httpv2.protocol.HTTPv2(file=None, length=None, **kwargs)[source]

Bases: HTTP[HTTPv2, HTTPv2]

This class implements Hypertext Transfer Protocol (HTTP/2).

The HTTP/2 frames it parses, by pcapkit.const.http.frame.Frame type:

Changed in version 1.6.0:

  • A payload opening with the connection preface parses, with the preface kept as preface and counted in length, and make() takes preface, since a dispatched HTTP/2 payload reaches this class rather than HTTP (#2524).

  • A whole frame after the first in a segment is a further layer of this class, where it was kept as Raw (#2536).

  • A SETTINGS frame the capture cut inside its settings parses, with the setting the cut lands inside read as zeros past it, as a cut DATA frame’s data is, and no setting past the data, where it was Raw (#2659, #2686, #2756).

  • Each enumeration field of make() and of the frame makers takes a member or an int code, resolved with the enumeration’s get; a name, a bool for a field wider than one bit, or a code the field cannot carry raises ProtocolError, rather than resolving against an enumeration inferred from the caller’s frame or writing a different value (#2594).

Removed in version 1.6.0: The type_default, type_namespace and type_reversed arguments of make(), and the error_default, error_namespace and error_reversed arguments of the RST_STREAM and GOAWAY frame makers; resolve a name with resolve_index() first (#2594).

__frame__: DefaultDict[Frame | int, str | tuple[Callable[[FrameType, HTTPv2], HTTPv2], Callable[[HTTPv2 | None, Any], Tuple[FrameType, Flags]]]]

Frame code to method mapping. A str value names the _read_http_${name} and _make_http_${name} methods, which fall back to _read_http_none and _make_http_none when not defined, as an unregistered code does; any other value is a (parser, constructor) pair of callables.

property alias: Literal['HTTP/2']

Acronym of current protocol.

property length: int

Header length of current protocol – the 9-octet frame header, after the 24-octet connection preface when one opens the payload.

property version: Literal['2']

Version of current protocol.

unpack(length=None, **kwargs)[source]

Unpack (parse) packet data.

Parameters:
  • length (int | None) – Length of packet data.

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

Return type:

HTTPv2

Returns:

Parsed packet data.

Raises:

ProtocolError – If the packet is malformed.

Notes

This guards ahead of Schema.unpack rather than leaving the check to read(), because a buffer shorter than the fixed 9-octet header cannot be parsed meaningfully. pkt['__length__'] there is decremented by each field’s nominal width regardless of how many octets the buffer had, so it goes negative and the frame payload’s length-derived fields (e.g. an unpadded DATA frame’s data: BytesField(length=lambda pkt: pkt['__length__'])) resolve to a negative width. Rejecting here keeps such a frame from reaching that arithmetic. An inner field can still drive it negative on a buffer that clears nine (e.g. a GOAWAY frame at 9-16 octets, whose fixed stream and error fields alone consume eight); the schema layer raises ProtocolError for that itself.

length is resolved against len() only for this method’s own check, and the original argument – None included – is what is forwarded to Protocol.unpack. Collapsing None to a concrete 0 would change what Schema.unpack’s own prepare decorator does with an exhausted stream: it raises StreamEOFError (an EOFError, the documented “no more packets” signal) only when the caller left length unspecified, and a resolved 0 would report an exhausted stream as a malformed packet. A non-zero short buffer is malformed either way, so it is rejected here whether or not length was given.

A payload opening with the HTTP/2 connection preface (RFC 9113 Section 3.4) has the frame parsed from the octets after it, as HTTP._guess_version parses it, since a dispatched payload reaches this class rather than that one (#2524); the preface counts towards length. A preface with no frame after it is refused, since the data model holds one frame per packet and has no form for a frameless segment.

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

Read Hypertext Transfer Protocol (HTTP/2).

Structure of HTTP/2 packet [RFC 7540]:

+-----------------------------------------------+
|                 Length (24)                   |
+---------------+---------------+---------------+
|   Type (8)    |   Flags (8)   |
+-+-------------+---------------+-------------------------------+
|R|                 Stream Identifier (31)                      |
+=+=============================================================+
|                   Frame Payload (0...)                      ...
+---------------------------------------------------------------+
Parameters:
  • length (int | None) – Length of packet data.

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

Return type:

HTTPv2

Returns:

Parsed packet data.

Raises:

ProtocolError – If the packet is malformed.

make(type=Frame.DATA, flags=0, reserved=0, sid=0, frame=None, payload=b'', preface=False, **kwargs)[source]

Make (construct) packet data.

Parameters:
  • type (Frame | int) – Type of HTTP/2 frame.

  • flags (Flags) – Flags of HTTP/2 frame, combined with those the frame constructor derives from frame.

  • reserved (int) – Reserved bit of the frame header.

  • sid (int) – Stream ID of HTTP/2 frame.

  • frame (bytes | HTTPv2 | FrameType | dict[str, Any] | None) – Frame data of HTTP/2 frame. Omitted (None), the frame type’s own default payload is built, as for {}; a bytes value, b'' included, is packed as raw octets.

  • payload (bytes | ProtocolBase | Schema) – Octets after the frame, e.g. the next frame.

  • preface (bool) – Whether the HTTP/2 connection preface goes ahead of the frame; pack() writes it.

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

Return type:

HTTPv2

Returns:

Constructed packet data.

Raises:

ProtocolError – If type is a name, a bool, or a member or code the 8-bit Type field cannot carry; or if frame is none of the forms this maker reads – raw bytes, a dict of frame arguments, an HTTPv2 data model or a Schema.

Changed in version 1.5.0:

  • reserved is a new parameter before sid, so a 1.4.x positional argument meant for sid or frame lands one parameter early (#1246).

  • frame defaults to None and dispatches to the frame type’s constructor, since the former b'' default is shorter than the payload a frame type of fixed or minimum size needs, so such a frame could not be built at all (#2274).

classmethod id()[source]

Index ID of the protocol.

RFC 9113 names the protocol HTTP/2.

Return type:

tuple[Literal['HTTP/2']]

Returns:

Index ID of the protocol.

Changed in version 1.6.0: ('HTTP/2',), narrowed to this class, where it was ('HTTP', 'HTTPv2') (#2524).

classmethod register_frame(code, meth)[source]

Register a frame parser.

Parameters:
Warns:

RegistryWarning – If a different entry is already registered for code; it is overwritten. Handing back the entry already stored, or one equal to it, is a silent no-op. The entry code shipped with is accepted like any other, so an override can be undone (#1362, #1363).

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (HTTPv2) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

_read_http_none(schema, *, header)[source]

Read HTTP packet with unassigned type.

Parameters:
Return type:

UnassignedFrame

Returns:

Parsed packet data.

_read_http_data(schema, *, header)[source]

Read HTTP/2 DATA frames.

Structure of HTTP/2 DATA frame [RFC 7540]:

+-----------------------------------------------+
|                 Length (24)                   |
+---------------+---------------+---------------+
|   Type (8)    |   Flags (8)   |
+-+-------------+---------------+-------------------------------+
|R|                 Stream Identifier (31)                      |
+---------------+-----------------------------------------------+
|Pad Length? (8)|
+---------------+-----------------------------------------------+
|                            Data (*)                         ...
+---------------------------------------------------------------+
|                           Padding (*)                       ...
+---------------------------------------------------------------+
Parameters:
  • schema (DataFrame) – Parsed frame schema.

  • header (HTTPv2) – Parsed HTTP/2 header schema.

Return type:

DataFrame

Returns:

Parsed packet data.

_read_http_headers(schema, *, header)[source]

Read HTTP/2 HEADERS frames.

Structure of HTTP/2 HEADERS frame [RFC 7540]:

+-----------------------------------------------+
|                 Length (24)                   |
+---------------+---------------+---------------+
|   Type (8)    |   Flags (8)   |
+-+-------------+---------------+-------------------------------+
|R|                 Stream Identifier (31)                      |
+---------------+-----------------------------------------------+
|Pad Length? (8)|
+-+-------------+-----------------------------------------------+
|E|                 Stream Dependency? (31)                     |
+-+-------------+-----------------------------------------------+
|  Weight? (8)  |
+-+-------------+-----------------------------------------------+
|                   Header Block Fragment (*)                 ...
+---------------------------------------------------------------+
|                           Padding (*)                       ...
+---------------------------------------------------------------+
Parameters:
  • schema (HeadersFrame) – Parsed frame schema.

  • header (HTTPv2) – Parsed HTTP/2 header schema.

Return type:

HeadersFrame

Returns:

Parsed packet data.

_read_http_priority(schema, *, header)[source]

Read HTTP/2 PRIORITY frames.

Structure of HTTP/2 PRIORITY frame [RFC 7540]:

+-----------------------------------------------+
|                 Length (24)                   |
+---------------+---------------+---------------+
|   Type (8)    |   Flags (8)   |
+-+-------------+---------------+-------------------------------+
|R|                 Stream Identifier (31)                      |
+-+-------------------------------------------------------------+
|E|                  Stream Dependency (31)                     |
+-+-------------+-----------------------------------------------+
|   Weight (8)  |
+-+-------------+
Parameters:
  • schema (PriorityFrame) – Parsed frame schema.

  • header (HTTPv2) – Parsed HTTP/2 header schema.

Return type:

PriorityFrame

Returns:

Parsed packet data.

Raises:

ProtocolError – If the packet is malformed.

_read_http_rst_stream(schema, *, header)[source]

Read HTTP/2 RST_STREAM frames.

Structure of HTTP/2 RST_STREAM frame [RFC 7540]:

+-----------------------------------------------+
|                 Length (24)                   |
+---------------+---------------+---------------+
|   Type (8)    |   Flags (8)   |
+-+-------------+---------------+-------------------------------+
|R|                 Stream Identifier (31)                      |
+---------------------------------------------------------------+
|                        Error Code (32)                        |
+---------------------------------------------------------------+
Parameters:
Return type:

RSTStreamFrame

Returns:

Parsed packet data.

Raises:

ProtocolError – If the packet is malformed.

_read_http_settings(schema, *, header)[source]

Read HTTP/2 SETTINGS frames.

Structure of HTTP/2 SETTINGS frame [RFC 7540]:

+-----------------------------------------------+
|                 Length (24)                   |
+---------------+---------------+---------------+
|   Type (8)    |   Flags (8)   |
+-+-------------+---------------+-------------------------------+
|R|                 Stream Identifier (31)                      |
+---------------------------------------------------------------+
|       Identifier (16)         |
+-------------------------------+-------------------------------+
|                        Value (32)                             |
+---------------------------------------------------------------+
|                          ......                               |
Parameters:
  • schema (SettingsFrame) – Parsed frame schema.

  • header (HTTPv2) – Parsed HTTP/2 header schema.

Return type:

SettingsFrame

Returns:

Parsed packet data.

Raises:

ProtocolError – If the packet is malformed.

_read_http_push_promise(schema, *, header)[source]

Read HTTP/2 PUSH_PROMISE frames.

Structure of HTTP/2 PUSH_PROMISE frame [RFC 7540]:

+-----------------------------------------------+
|                 Length (24)                   |
+---------------+---------------+---------------+
|   Type (8)    |   Flags (8)   |
+-+-------------+---------------+-------------------------------+
|R|                 Stream Identifier (31)                      |
+---------------+-----------------------------------------------+
|Pad Length? (8)|
+-+-------------+-----------------------------------------------+
|R|                  Promised Stream ID (31)                    |
+-+-----------------------------+-------------------------------+
|                   Header Block Fragment (*)                 ...
+---------------------------------------------------------------+
|                           Padding (*)                       ...
+---------------------------------------------------------------+
Parameters:
Return type:

PushPromiseFrame

Returns:

Parsed packet data.

Raises:

ProtocolError – If the packet is malformed.

_read_http_ping(schema, *, header)[source]

Read HTTP/2 PING frames.

Structure of HTTP/2 PING frame [RFC 7540]:

+-----------------------------------------------+
|                 Length (24)                   |
+---------------+---------------+---------------+
|   Type (8)    |   Flags (8)   |
+-+-------------+---------------+-------------------------------+
|R|                 Stream Identifier (31)                      |
+---------------------------------------------------------------+
|                                                               |
|                      Opaque Data (64)                         |
|                                                               |
+---------------------------------------------------------------+
Parameters:
  • schema (PingFrame) – Parsed frame schema.

  • header (HTTPv2) – Parsed HTTP/2 header schema.

Return type:

PingFrame

Returns:

Parsed packet data.

Raises:

ProtocolError – If the packet is malformed.

_read_http_goaway(schema, *, header)[source]

Read HTTP/2 GOAWAY frames.

Structure of HTTP/2 GOAWAY frame [RFC 7540]:

+-----------------------------------------------+
|                 Length (24)                   |
+---------------+---------------+---------------+
|   Type (8)    |   Flags (8)   |
+-+-------------+---------------+-------------------------------+
|R|                 Stream Identifier (31)                      |
+-+-------------+---------------+-------------------------------+
|R|                  Last-Stream-ID (31)                        |
+-+-------------------------------------------------------------+
|                      Error Code (32)                          |
+---------------------------------------------------------------+
|                  Additional Debug Data (*)                    |
+---------------------------------------------------------------+
Parameters:
  • schema (GoawayFrame) – Parsed frame schema.

  • header (HTTPv2) – Parsed HTTP/2 header schema.

Return type:

GoawayFrame

Returns:

Parsed packet data.

_read_http_window_update(schema, *, header)[source]

Read HTTP/2 WINDOW_UPDATE frames.

Structure of HTTP/2 WINDOW_UPDATE frame [RFC 7540]:

+-----------------------------------------------+
|                 Length (24)                   |
+---------------+---------------+---------------+
|   Type (8)    |   Flags (8)   |
+-+-------------+---------------+-------------------------------+
|R|                 Stream Identifier (31)                      |
+-+-------------+---------------+-------------------------------+
|R|              Window Size Increment (31)                     |
+-+-------------------------------------------------------------+
Parameters:
Return type:

WindowUpdateFrame

Returns:

Parsed packet data.

Raises:

ProtocolError – If the packet is malformed.

_read_http_continuation(schema, *, header)[source]

Read HTTP/2 CONTINUATION frames.

Structure of HTTP/2 CONTINUATION frame [RFC 7540]:

+-----------------------------------------------+
|                 Length (24)                   |
+---------------+---------------+---------------+
|   Type (8)    |   Flags (8)   |
+-+-------------+---------------+-------------------------------+
|R|                 Stream Identifier (31)                      |
+---------------------------------------------------------------+
|                   Header Block Fragment (*)                 ...
+---------------------------------------------------------------+
Parameters:
Return type:

ContinuationFrame

Returns:

Parsed packet data.

_make_http_none(frame=None, *, data=b'', **kwargs)[source]

Make HTTP/2 unassigned frame type.

Parameters:
  • frame (UnassignedFrame | None) – Frame data model.

  • data (bytes) – Unspecified frame data.

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

Return type:

tuple[UnassignedFrame, Flags]

Returns:

Constructed frame schema and updated flags.

_make_http_data(frame=None, *, end_stream=False, padded=False, pad_len=0, data=b'', padding=b'', **kwargs)[source]

Make HTTP/2 DATA frame.

Parameters:
  • frame (DataFrame | None) – Frame data model.

  • end_stream (bool) – End of stream flag.

  • padded (bool) – Padded flag, implied by a non-zero pad_len.

  • pad_len (int) – Padding length.

  • data (bytes) – Frame data.

  • padding (bytes) – Padding octets, truncated or zero-filled to pad_len octets.

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

Return type:

tuple[DataFrame, Flags]

Returns:

Constructed frame schema and updated flags.

_make_http_headers(frame=None, *, end_stream=False, end_headers=False, padded=False, pad_len=0, excl_dep=False, sid_dep=None, weight=0, fragment=b'', padding=b'', **kwargs)[source]

Make HTTP/2 HEADERS frame.

Parameters:
  • frame (HeadersFrame | None) – Frame data model.

  • end_stream (bool) – End of stream flag.

  • end_headers (bool) – End of headers flag.

  • padded (bool) – Padded flag, implied by a non-zero pad_len.

  • pad_len (int) – Padding length.

  • excl_dep (bool) – Exclusive dependency flag.

  • sid_dep (int | None) – Dependency stream identifier. Giving one sets the PRIORITY flag.

  • weight (int) – Priority weight value.

  • fragment (bytes) – Header block fragment.

  • padding (bytes) – Padding octets, truncated or zero-filled to pad_len octets.

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

Return type:

tuple[HeadersFrame, Flags]

Returns:

Constructed frame schema and updated flags.

_make_http_priority(frame=None, *, sid_dep=0, excl_dep=False, weight=0, **kwargs)[source]

Make HTTP/2 PRIORITY frame.

Parameters:
  • frame (PriorityFrame | None) – Frame data model.

  • excl_dep (bool) – Exclusive dependency flag.

  • sid_dep (int) – Dependency stream identifier.

  • weight (int) – Priority weight value.

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

Return type:

tuple[PriorityFrame, Flags]

Returns:

Constructed frame schema and updated flags.

_make_http_rst_stream(frame=None, *, error=ErrorCode.NO_ERROR, **kwargs)[source]

Make HTTP/2 RST_STREAM frame.

Parameters:
Return type:

tuple[RSTStreamFrame, Flags]

Returns:

Constructed frame schema and updated flags.

Raises:

ProtocolError – If error is a name, a bool, or a member or code the 32-bit Error Code field cannot carry.

Changed in version 1.5.0: error defaults to NO_ERROR, the code RFC 9113 Section 7 gives a condition that is not the result of an error, rather than HTTP_1_1_REQUIRED, which asks the peer to use HTTP/1.1 instead (#2311).

_make_http_settings(frame=None, *, ack=False, settings=None, **kwargs)[source]

Make HTTP/2 SETTINGS frame.

Parameters:
Return type:

tuple[SettingsFrame, Flags]

Returns:

Constructed frame schema and updated flags.

Raises:

ProtocolError – If settings is not bytes, a dict, a list or None, or if an identifier other than a SettingPair’s is a name, a bool, or a member or code the 16-bit Identifier field cannot carry.

Changed in version 1.5.0: settings of None, the default, builds a SETTINGS frame with no parameters, which RFC 9113 Section 6.5 permits, rather than being rejected (#2274).

Changed in version 1.6.0: A frame the capture cut inside its settings, as its __short_read__ records, packs the settings its parse read from the octets its packet holds with zeros after them to the Length it declares, since that parse reads no setting past the data, so its rebuild declares that Length too; with its settings edited, the Length is computed as for a whole frame (#2756).

_make_http_push_promise(frame=None, *, end_headers=False, padded=False, pad_len=0, promised_reserved=0, promised_sid=0, fragment=b'', padding=b'', **kwargs)[source]

Make HTTP/2 PUSH_PROMISE frame.

Parameters:
  • frame (PushPromiseFrame | None) – Frame data model.

  • end_headers (bool) – End of headers flag.

  • padded (bool) – Padded flag, implied by a non-zero pad_len.

  • pad_len (int) – Padding length.

  • promised_reserved (int) – Reserved bit of the promised stream identifier.

  • promised_sid (int) – Promised stream identifier.

  • fragment (bytes) – Header block fragment.

  • padding (bytes) – Padding octets, truncated or zero-filled to pad_len octets.

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

Return type:

tuple[PushPromiseFrame, Flags]

Returns:

Constructed frame schema and updated flags.

_make_http_ping(frame=None, *, ack=False, opaque_data=bytes(8), **kwargs)[source]

Make HTTP/2 PING frame.

Parameters:
  • frame (PingFrame | None) – Frame data model.

  • ack (bool) – Acknowledge flag.

  • opaque_data (bytes) – Opaque data, exactly 8 octets.

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

Return type:

tuple[PingFrame, Flags]

Returns:

Constructed frame schema and updated flags.

Raises:

ProtocolError – If opaque_data is not 8 octets long.

_make_http_goaway(frame=None, *, last_reserved=0, last_sid=0, error=ErrorCode.NO_ERROR, debug_data=b'', **kwargs)[source]

Make HTTP/2 GOAWAY frame.

Parameters:
  • frame (GoawayFrame | None) – Frame data model.

  • last_reserved (int) – Reserved bit of the last stream identifier.

  • last_sid (int) – Last stream identifier.

  • error (ErrorCode | int) – Error code, NO_ERROR unless given.

  • debug_data (bytes) – Additional debug data.

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

Return type:

tuple[GoawayFrame, Flags]

Returns:

Constructed frame schema and updated flags.

Raises:

ProtocolError – If error is a name, a bool, or a member or code the 32-bit Error Code field cannot carry.

Changed in version 1.5.0: error defaults to NO_ERROR, the code RFC 9113 Section 7 gives a condition that is not the result of an error, rather than HTTP_1_1_REQUIRED, which asks the peer to use HTTP/1.1 instead (#2311).

_make_http_window_update(frame=None, *, incr_reserved=0, incr=0, **kwargs)[source]

Make HTTP/2 WINDOW_UPDATE frame.

Parameters:
  • frame (WindowUpdateFrame | None) – Frame data model.

  • incr_reserved (int) – Reserved bit of the window size increment.

  • incr (int) – Window size increment.

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

Return type:

tuple[WindowUpdateFrame, Flags]

Returns:

Constructed frame schema and updated flags.

_make_http_continuation(frame=None, *, end_headers=False, fragment=b'', **kwargs)[source]

Make HTTP/2 CONTINUATION frame.

Parameters:
  • frame (ContinuationFrame | None) – Frame data model.

  • end_headers (bool) – End of headers flag.

  • fragment (bytes) – Header block fragment.

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

Return type:

tuple[ContinuationFrame, Flags]

Returns:

Constructed frame schema and updated flags.

Header Schemas

Removed in version 1.6.0: pcapkit.protocols.schema.application.httpv2, with no alias: the module moved here (#2534).

Removed in version 1.6.0: pcapkit.protocols.schema.application.httpv2.HTTP, with no alias. The class is renamed HTTPv2, after its module (#2529).

class pcapkit.protocols.application.httpv2.schema.HTTPv2(length=NO_VALUE, type=NO_VALUE, flags=NO_VALUE, stream=NO_VALUE, frame=NO_VALUE, payload=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: Schema

Header schema for HTTP/2 packet.

length: int = <NumberField length>

Length of the frame payload, the 9-octet header excluded.

type: Frame = <EnumField type>

Frame type.

flags: FrameFlags = <BitField flags>

Frame specific flags.

stream: StreamID = <BitField stream>

Stream identifier.

frame: FrameType = <SwitchField frame>

Frame payload.

payload: bytes = <PayloadField payload>

Octets after the frame, e.g. the next frame.

class pcapkit.protocols.application.httpv2.schema.FrameType(*args, **kwargs)[source]

Bases: EnumSchema[Frame]

Header schema for HTTP/2 frame payload.

class Flags(*values)[source]

Bases: EnumLookup, IntFlag

Flags enumeration for HTTP/2 frames.

Built on EnumLookup, the lookup contract shared by every non-registry enumeration. The concrete per-frame subclasses below each declare class Flags(FrameType.Flags): with no base list of their own, so they inherit EnumLookup transitively rather than needing it repeated.

post_process(packet)[source]

Revise schema data after unpacking process.

Parameters:

packet (dict[str, Any]) – Unpacked data.

Return type:

Schema

Returns:

Revised schema.

class pcapkit.protocols.application.httpv2.schema.UnassignedFrame(data=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: FrameType

Header schema for unassigned HTTP/2 frame payload.

data: bytes = <BytesField data>

Frame payload.

class pcapkit.protocols.application.httpv2.schema.DataFrame(pad_len=NO_VALUE, data=NO_VALUE, padding=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: FrameType

Header schema for HTTP/2 DATA frames.

class Flags(*values)[source]

Bases: Flags

Flags enumeration for HTTP/2 DATA frames.

pad_len: int = <ConditionalField pad_len>

Padding length.

data: bytes = <BytesField data>

Data.

padding: bytes = <ConditionalField padding>

Padding.

class pcapkit.protocols.application.httpv2.schema.HeadersFrame(pad_len=NO_VALUE, stream_dep=NO_VALUE, weight=NO_VALUE, fragment=NO_VALUE, padding=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: FrameType

Header schema for HTTP/2 HEADERS frames.

class Flags(*values)[source]

Bases: Flags

Flags enumeration for HTTP/2 HEADERS frames.

pad_len: int = <ConditionalField pad_len>

Padding length.

stream_dep: StreamDependency = <ConditionalField stream_dep>

Stream dependency.

weight: int = <ConditionalField weight>

Weight.

fragment: bytes = <BytesField fragment>

Header block fragment.

padding: bytes = <ConditionalField padding>

Padding.

class pcapkit.protocols.application.httpv2.schema.PriorityFrame(stream=NO_VALUE, weight=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: FrameType

Header schema for HTTP/2 PRIORITY frames.

stream: StreamDependency = <BitField stream>

Stream dependency (exclusive, stream ID).

weight: int = <UInt8Field weight>

Weight.

class pcapkit.protocols.application.httpv2.schema.RSTStreamFrame(error=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: FrameType

Header schema for HTTP/2 RST_STREAM frames.

error: ErrorCode = <EnumField error>

Error code.

class pcapkit.protocols.application.httpv2.schema.SettingPair(id=NO_VALUE, value=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: Schema

Header schema for HTTP/2 SETTINGS frame setting pairs.

id: Setting = <EnumField id>

Identifier.

value: int = <UInt32Field value>

Value.

class pcapkit.protocols.application.httpv2.schema.SettingsFrame(settings=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: FrameType

Header schema for HTTP/2 SETTINGS frames.

class Flags(*values)[source]

Bases: Flags

Flags enumeration for HTTP/2 SETTINGS frames.

settings: list[SettingPair] = <ListField settings>

Settings.

class pcapkit.protocols.application.httpv2.schema.PushPromiseFrame(pad_len=NO_VALUE, stream=NO_VALUE, fragment=NO_VALUE, padding=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: FrameType

Header schema for HTTP/2 PUSH_PROMISE frames.

class Flags(*values)[source]

Bases: Flags

Flags enumeration for HTTP/2 PUSH_PROMISE frames.

pad_len: int = <ConditionalField pad_len>

Padding length.

stream: StreamID = <BitField stream>

Promised stream ID.

fragment: bytes = <BytesField fragment>

Header block fragment.

padding: bytes = <ConditionalField padding>

Padding.

class pcapkit.protocols.application.httpv2.schema.PingFrame(data=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: FrameType

Header schema for HTTP/2 PING frames.

class Flags(*values)[source]

Bases: Flags

Flags enumeration for HTTP/2 PING frames.

data: bytes = <BytesField data>

Opaque data.

class pcapkit.protocols.application.httpv2.schema.GoawayFrame(stream=NO_VALUE, error=NO_VALUE, debug=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: FrameType

Header schema for HTTP/2 GOAWAY frames.

stream: StreamID = <BitField stream>

Last stream ID.

error: ErrorCode = <EnumField error>

Error code.

debug: bytes = <BytesField debug>

Additional debug data.

class pcapkit.protocols.application.httpv2.schema.WindowUpdateFrame(size=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: FrameType

Header schema for HTTP/2 WINDOW_UPDATE frames.

size: WindowSize = <BitField size>

Window size increment.

class pcapkit.protocols.application.httpv2.schema.ContinuationFrame(fragment=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: FrameType

Header schema for HTTP/2 CONTINUATION frames.

class Flags(*values)[source]

Bases: Flags

Flags enumeration for HTTP/2 CONTINUATION frames.

fragment: bytes = <BytesField fragment>

Header block fragment.

Type Stubs

class pcapkit.protocols.application.httpv2.schema.FrameFlags[source]

Bases: TypedDict

HTTP frame specific flags.

class pcapkit.protocols.application.httpv2.schema.StreamID[source]

Bases: TypedDict

Stream identifier.

reserved: int

Reserved bit.

sid: int

Stream identifier.

class pcapkit.protocols.application.httpv2.schema.StreamDependency[source]

Bases: TypedDict

Stream dependency.

exclusive: int

Exclusive flag.

sid: int

Stream dependency identifier.

class pcapkit.protocols.application.httpv2.schema.WindowSize[source]

Bases: TypedDict

Window size increment.

reserved: int

Reserved bit.

incr: int

Window size increment.

Auxiliary Functions

pcapkit.protocols.application.httpv2.schema.http_frame_selector(pkt)[source]

Selector function for HTTPv2.frame field.

Parameters:

pkt (dict[str, Any]) – Packet data.

Return type:

FieldBase

Returns:

Returns a SchemaField wrapped FrameType instance.

Data Models

Removed in version 1.6.0: pcapkit.protocols.data.application.httpv2, with no alias: the module moved here (#2534).

Removed in version 1.6.0: pcapkit.protocols.data.application.httpv2.HTTP, with no alias. The class is renamed HTTPv2, after its module (#2529).

class pcapkit.protocols.application.httpv2.data.HTTPv2(*args, **kwargs)[source]

Bases: Protocol

Data model for HTTP/2 protocol.

length: int

Length of the frame payload, the 9-octet header excluded.

type: Frame

Frame type.

flags: Flags

Flags.

reserved: int

Reserved bit of the frame header.

sid: int

Stream ID.

class pcapkit.protocols.application.httpv2.data.Flags(*args, **kwargs)[source]

Bases: Data

Data model for HTTP/2 flags.

class pcapkit.protocols.application.httpv2.data.UnassignedFrame(length, type, reserved, sid, flags, data)[source]

Bases: HTTPv2

Data model for HTTP/2 unassigned frame.

flags: Flags

Flags.

data: bytes

Frame payload.

class pcapkit.protocols.application.httpv2.data.DataFrame(length, type, reserved, sid, flags, pad_len, data, padding)[source]

Bases: HTTPv2

Data model for HTTP/2 DATA frame.

flags: DataFrameFlags

Flags.

pad_len: int

Padding length.

data: bytes

Frame payload.

padding: bytes

Padding octets, as captured (empty unless PADDED).

class pcapkit.protocols.application.httpv2.data.DataFrameFlags(END_STREAM, PADDED)[source]

Bases: Flags

Data model for HTTP/2 DATA frame flags.

END_STREAM: bool

END_STREAM flag.

PADDED: bool

PADDED flag.

class pcapkit.protocols.application.httpv2.data.HeadersFrame(length, type, reserved, sid, flags, pad_len, excl_dependency, stream_dependency, weight, fragment, padding)[source]

Bases: HTTPv2

Data model for HTTP/2 HEADERS frame.

flags: HeadersFrameFlags

Flags.

pad_len: int

Padding length.

excl_dependency: bool

Exclusive dependency.

stream_dependency: int

Stream dependency.

weight: int

Weight.

fragment: bytes

Header block fragment.

padding: bytes

Padding octets, as captured (empty unless PADDED).

class pcapkit.protocols.application.httpv2.data.HeadersFrameFlags(END_STREAM, END_HEADERS, PADDED, PRIORITY)[source]

Bases: Flags

Data model for HTTP/2 HEADERS frame flags.

END_STREAM: bool

END_STREAM flag.

END_HEADERS: bool

END_HEADERS flag.

PADDED: bool

PADDED flag.

PRIORITY: bool

PRIORITY flag.

class pcapkit.protocols.application.httpv2.data.PriorityFrame(length, type, reserved, sid, flags, excl_dependency, stream_dependency, weight)[source]

Bases: HTTPv2

Data model for HTTP/2 PRIORITY frame.

flags: Flags

Flags.

excl_dependency: bool

Exclusive dependency.

stream_dependency: int

Stream dependency.

weight: int

Weight.

class pcapkit.protocols.application.httpv2.data.RSTStreamFrame(length, type, reserved, sid, flags, error)[source]

Bases: HTTPv2

Data model for HTTP/2 RST_STREAM frame.

flags: Flags

Flags.

error: ErrorCode

Error code.

class pcapkit.protocols.application.httpv2.data.SettingsFrame(length, type, reserved, sid, flags, settings)[source]

Bases: HTTPv2

Data model for HTTP/2 SETTINGS frame.

flags: SettingsFrameFlags

Flags.

settings: Settings

Settings.

class pcapkit.protocols.application.httpv2.data.Settings(mapping=None)[source]

Bases: OrderedMultiInfo[Setting, int]

Settings of an HTTP/2 SETTINGS frame.

An identifier may repeat, and the values apply in order, so the last one wins (RFC 9113 Section 6.5). Every entry is kept in wire order, as getlist() and items(multi=True) show and the rebuild writes, but indexing, get(), values(), items() and to_dict(flat=True) answer with the last value of each identifier rather than the first.

It is immutable, as an OrderedMultiInfo is, so it is built from the (identifier, value) pairs in one go, and to_dict() exports every pair as a plain OrderedMultiDict.

items(multi=False)[source]

Return the (key, value) pairs.

Parameters:

multi (bool) – If set to True, an iterator with a pair for each value of each key, as to_dict() writes them. Otherwise a view of the pairs of the first value of each key, as the items method of collections.abc.Mapping returns.

Return type:

Iterator[tuple[Setting, int]]

class pcapkit.protocols.application.httpv2.data.SettingsFrameFlags(ACK)[source]

Bases: Flags

Data model for HTTP/2 SETTINGS frame flags.

ACK: bool

ACK flag.

class pcapkit.protocols.application.httpv2.data.PushPromiseFrame(length, type, reserved, sid, flags, pad_len, promised_reserved, promised_sid, fragment, padding)[source]

Bases: HTTPv2

Data model for HTTP/2 PUSH_PROMISE frame.

flags: PushPromiseFrameFlags

Flags.

pad_len: int

Padding length.

promised_reserved: int

Reserved bit of the promised stream ID.

promised_sid: int

Promised stream ID.

fragment: bytes

Header block fragment.

padding: bytes

Padding octets, as captured (empty unless PADDED).

class pcapkit.protocols.application.httpv2.data.PushPromiseFrameFlags(END_HEADERS, PADDED)[source]

Bases: Flags

Data model for HTTP/2 PUSH_PROMISE frame flags.

END_HEADERS: bool

END_HEADERS flag.

PADDED: bool

PADDED flag.

class pcapkit.protocols.application.httpv2.data.PingFrame(length, type, reserved, sid, flags, data)[source]

Bases: HTTPv2

Data model for HTTP/2 PING frame.

flags: PingFrameFlags

Flags.

data: bytes

Opaque data.

class pcapkit.protocols.application.httpv2.data.PingFrameFlags(ACK)[source]

Bases: Flags

Data model for HTTP/2 PING frame flags.

ACK: bool

ACK flag.

class pcapkit.protocols.application.httpv2.data.GoawayFrame(length, type, reserved, sid, flags, last_reserved, last_sid, error, debug_data)[source]

Bases: HTTPv2

Data model for HTTP/2 GOAWAY frame.

flags: Flags

Flags.

last_reserved: int

Reserved bit of the last stream ID.

last_sid: int

Last stream ID.

error: ErrorCode

Error code.

debug_data: bytes

Additional debug data.

class pcapkit.protocols.application.httpv2.data.WindowUpdateFrame(length, type, reserved, sid, flags, increment_reserved, increment)[source]

Bases: HTTPv2

Data model for HTTP/2 WINDOW_UPDATE frame.

flags: Flags

Flags.

increment_reserved: int

Reserved bit of the window size increment.

increment: int

Window size increment.

class pcapkit.protocols.application.httpv2.data.ContinuationFrame(length, type, reserved, sid, flags, fragment)[source]

Bases: HTTPv2

Data model for HTTP/2 CONTINUATION frame.

flags: ContinuationFrameFlags

Flags.

fragment: bytes

Header block fragment.

class pcapkit.protocols.application.httpv2.data.ContinuationFrameFlags(END_HEADERS)[source]

Bases: Flags

Data model for HTTP/2 CONTINUATION frame flags.

END_HEADERS: bool

END_HEADERS flag.

Footnotes