HTTP/2 - Hypertext Transfer Protocol

pcapkit.protocols.application.httpv2 contains HTTP only, which implements extractor for Hypertext Transfer Protocol (HTTP/2) *, whose structure is described as below:

Octets

Bits

Name

Description

0

0

http.length

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


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

Bases: HTTP[HTTP]

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

This class currently supports parsing of the following HTTP/2 frames, which are directly mapped to the pcapkit.const.http.frame.Frame enumeration:

Frame Code

Frame Parser

DATA

_read_http_data()

HEADERS

_read_http_headers()

PRIORITY

_read_http_priority()

RST_STREAM

_read_http_rst_stream()

SETTINGS

_read_http_settings()

PUSH_PROMISE

_read_http_push_promise()

PING

_read_http_ping()

GOAWAY

_read_http_goaway()

WINDOW_UPDATE

_read_http_window_update()

CONTINUATION

_read_http_continuation()

Parameters
  • *args (Any) – Arbitrary positional arguments.

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

Return type

Protocol[PT]

property alias: Literal['HTTP/2']

Acronym of current protocol.

Return type

Literal[‘HTTP/2’]

property length: Literal[9]

Header length of current protocol.

Return type

Literal[9]

property version: Literal['2']

Version of current protocol.

Return type

Literal[‘2’]

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 (Optional[int]) – Length of packet data.

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

Return type

HTTP

Returns

Parsed packet data.

Raises

ProtocolError – If the packet is malformed.

make(**kwargs)[source]

Make (construct) packet data.

Parameters

**kwargs (Any) – Arbitrary keyword arguments.

Return type

NoReturn

Returns

Constructed packet data.

classmethod id()[source]

Index ID of the protocol.

Returns

Index ID of the protocol.

Return type

tuple[Literal[“HTTP”]]

classmethod register_frame(code, meth)[source]

Register a frame parser.

Parameters
  • code (RegType_Frame) – HTTP frame type code.

  • meth (str | FrameParser) – Method name or callable to parse the frame.

Return type

None

_read_http_none(frame, length, flags, sid)[source]

Read HTTP packet with unassigned type.

Parameters
  • frame (Frame) – Frame type.

  • length (int) – Length of packet data.

  • flags (str) – Flags of the frame.

  • sid (int) – Stream ID.

Return type

UnassignedFrame

Returns

Parsed packet data.

Raises

ProtocolError – If the packet is malformed.

_read_http_data(frame, length, flags, sid)[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
  • frame (Frame) – Frame type.

  • length (int) – Length of packet data.

  • flags (str) – Flags of the frame.

  • sid (int) – Stream ID.

Return type

DataFrame

Returns

Parsed packet data.

Raises

ProtocolError – If the packet is malformed.

_read_http_headers(frame, length, flags, sid)[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
  • frame (Frame) – Frame type.

  • length (int) – Length of packet data.

  • flags (str) – Flags of the frame.

  • sid (int) – Stream ID.

Return type

HeadersFrame

Returns

Parsed packet data.

Raises

ProtocolError – If the packet is malformed.

_read_http_priority(frame, length, flags, sid)[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
  • frame (Frame) – Frame type.

  • length (int) – Length of packet data.

  • flags (str) – Flags of the frame.

  • sid (int) – Stream ID.

Return type

PriorityFrame

Returns

Parsed packet data.

Raises

ProtocolError – If the packet is malformed.

_read_http_rst_stream(frame, length, flags, sid)[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
  • frame (Frame) – Frame type.

  • length (int) – Length of packet data.

  • flags (str) – Flags of the frame.

  • sid (int) – Stream ID.

Return type

RstStreamFrame

Returns

Parsed packet data.

Raises

ProtocolError – If the packet is malformed.

_read_http_settings(frame, length, flags, sid)[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
  • frame (Frame) – Frame type.

  • length (int) – Length of packet data.

  • flags (str) – Flags of the frame.

  • sid (int) – Stream ID.

Return type

SettingsFrame

Returns

Parsed packet data.

Raises

ProtocolError – If the packet is malformed.

_read_http_push_promise(frame, length, flags, sid)[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
  • frame (Frame) – Frame type.

  • length (int) – Length of packet data.

  • flags (str) – Flags of the frame.

  • sid (int) – Stream ID.

Return type

PushPromiseFrame

Returns

Parsed packet data.

Raises

ProtocolError – If the packet is malformed.

_read_http_ping(frame, length, flags, sid)[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
  • frame (Frame) – Frame type.

  • length (int) – Length of packet data.

  • flags (str) – Flags of the frame.

  • sid (int) – Stream ID.

Return type

PingFrame

Returns

Parsed packet data.

Raises

ProtocolError – If the packet is malformed.

_read_http_goaway(frame, length, flags, sid)[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
  • frame (Frame) – Frame type.

  • length (int) – Length of packet data.

  • flags (str) – Flags of the frame.

  • sid (int) – Stream ID.

Return type

GoawayFrame

Returns

Parsed packet data.

Raises

ProtocolError – If the packet is malformed.

_read_http_window_update(frame, length, flags, sid)[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
  • frame (Frame) – Frame type.

  • length (int) – Length of packet data.

  • flags (str) – Flags of the frame.

  • sid (int) – Stream ID.

Return type

WindowUpdateFrame

Returns

Parsed packet data.

Raises

ProtocolError – If the packet is malformed.

_read_http_continuation(frame, length, flags, sid)[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
  • frame (Frame) – Frame type.

  • length (int) – Length of packet data.

  • flags (str) – Flags of the frame.

  • sid (int) – Stream ID.

Return type

ContinuationFrame

Returns

Parsed packet data.

Raises

ProtocolError – If the packet is malformed.

__frame__: DefaultDict[int, str | FrameParser]

Frame code to method mapping, c.f. read(). Method names are expected to be referred to the class by _read_http_${name}, and if such name not found, the value should then be a method that can parse the frame by itself.

Type

DefaultDict[RegType_Frame, str | FrameParser]

Data Structures

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

Bases: HTTP

Data model for HTTP/2 protocol.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

length: int

Length.

type: Frame

Frame type.

flags: Optional[Flags]

Flags.

sid: int

Stream ID.

class pcapkit.protocols.data.application.httpv2.Flags[source]

Bases: Info

Data model for HTTP/2 flags.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

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

Bases: HTTP

Data model for HTTP/2 unassigned frame.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

data: Optional[bytes]

Frame payload.

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

Bases: HTTP

Data model for HTTP/2 DATA frame.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

flags: DataFrameFlags

Flags.

pad_len: int

Padded length.

data: Optional[bytes]

Frame payload.

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

Bases: Flags

Data model for HTTP/2 DATA frame flags.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

END_STREAM: bool

END_STREAM flag.

PADDED: bool

PADDED flag.

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

Bases: HTTP

Data model for HTTP/2 HEADERS frame.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

flags: HeadersFrameFlags

Flags.

pad_len: int

Padded length.

excl_dependency: Optional[bool]

Exclusive dependency.

stream_dependency: Optional[int]

Stream dependency.

weight: Optional[int]

Weight.

fragment: Optional[bytes]

Header block fragment.

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

Bases: Flags

Data model for HTTP/2 HEADERS frame flags.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

END_STREAM: bool

END_STREAM flag.

END_HEADERS: bool

END_HEADERS flag.

PADDED: bool

PADDED flag.

PRIORITY: bool

PRIORITY flag.

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

Bases: HTTP

Data model for HTTP/2 PRIORITY frame.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

flags: Literal[None]

Flags.

excl_dependency: bool

Exclusive dependency.

stream_dependency: int

Stream dependency.

weight: int

Weight.

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

Bases: HTTP

Data model for HTTP/2 RST_STREAM frame.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

flags: Literal[None]

Flags.

error: ErrorCode

Error code.

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

Bases: HTTP

Data model for HTTP/2 SETTINGS frame.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

flags: SettingsFrameFlags

Flags.

settings: OrderedMultiDict[Setting, int]

Settings.

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

Bases: Flags

Data model for HTTP/2 SETTINGS frame flags.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

ACK: bool

ACK flag.

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

Bases: HTTP

Data model for HTTP/2 PUSH_PROMISE frame.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

flags: PushPromiseFrameFlags

Flags.

pad_len: int

Padded length.

promised_sid: int

Promised stream ID.

fragment: Optional[bytes]

Header block fragment.

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

Bases: Flags

Data model for HTTP/2 PUSH_PROMISE frame flags.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

END_HEADERS: bool

END_HEADERS flag.

PADDED: bool

PADDED flag.

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

Bases: HTTP

Data model for HTTP/2 PING frame.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

flags: PingFrameFlags

Flags.

data: bytes

Opaque data.

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

Bases: Flags

Data model for HTTP/2 PING frame flags.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

ACK: bool

ACK flag.

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

Bases: HTTP

Data model for HTTP/2 GOAWAY frame.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

flags: Literal[None]

Flags.

last_sid: int

Last stream ID.

error: ErrorCode

Error code.

debug_data: Optional[bytes]

Additional debug data.

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

Bases: HTTP

Data moddel for HTTP/2 WINDOW_UPDATE frame.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

flags: Literal[None]

Flags.

increment: int

Window size increment.

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

Bases: HTTP

Data model for HTTP/2 CONTINUATION frame.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

flags: ContinuationFrameFlags

Flags.

fragment: Optional[bytes]

Header block fragment.

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

Bases: Flags

Data model for HTTP/2 CONTINUATION frame flags.

Parameters
  • *args (VT) – Arbitrary positional arguments.

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

Return type

Info

END_HEADERS: bool

END_HEADERS flag.


*

https://en.wikipedia.org/wiki/HTTP/2