HTTP/2 - Hypertext Transfer Protocol

pcapkit.protocols.application.httpv2 contains HTTPv2 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.HTTPv2(file=None, length=None, **kwargs)[source]

Bases: pcapkit.protocols.application.http.HTTP

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

__length_hint__()[source]

Total length of corresponding protocol.

Return type

Literal[9]

_read_http_continuation(size, kind, flag)[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
  • size (int) – length of packet data

  • kind (int) – packet type

  • flag (str) – packet flags (8 bits)

Returns

Parsed packet data.

Return type

DataType_HTTPv2_CONTINUATION

Raises

ProtocolError – If the packet is malformed.

_read_http_data(size, kind, flag)[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
  • size (int) – length of packet data

  • kind (int) – packet type

  • flag (str) – packet flags (8 bits)

Returns

Parsed packet data.

Return type

DataType_HTTPv2_DATA

Raises

ProtocolError – If the packet is malformed.

_read_http_goaway(size, kind, flag)[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
  • size (int) – length of packet data

  • kind (int) – packet type

  • flag (str) – packet flags (8 bits)

Returns

Parsed packet data.

Return type

DataType_HTTPv2_GOAWAY

Raises

ProtocolError – If the packet is malformed.

_read_http_headers(size, kind, flag)[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
  • size (int) – length of packet data

  • kind (int) – packet type

  • flag (str) – packet flags (8 bits)

Returns

Parsed packet data.

Return type

DataType_HTTPv2_HEADERS

Raises

ProtocolError – If the packet is malformed.

_read_http_none(size, kind, flag)[source]

Read HTTP packet with unassigned type.

Parameters
  • size (int) – length of packet data

  • kind (int) – packet type

  • flag (str) – packet flags (8 bits)

Returns

Parsed packet data.

Return type

DataType_HTTPv2_Unassigned

Raises

ProtocolError – If the packet is malformed.

_read_http_ping(size, kind, flag)[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
  • size (int) – length of packet data

  • kind (int) – packet type

  • flag (str) – packet flags (8 bits)

Returns

Parsed packet data.

Return type

DataType_HTTPv2_PING

Raises

ProtocolError – If the packet is malformed.

_read_http_priority(size, kind, flag)[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
  • size (int) – length of packet data

  • kind (int) – packet type

  • flag (str) – packet flags (8 bits)

Returns

Parsed packet data.

Return type

DataType_HTTPv2_PRIORITY

Raises

ProtocolError – If the packet is malformed.

_read_http_push_promise(size, kind, flag)[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
  • size (int) – length of packet data

  • kind (int) – packet type

  • flag (str) – packet flags (8 bits)

Returns

Parsed packet data.

Return type

DataType_HTTPv2_PUSH_PROMISE

Raises

ProtocolError – If the packet is malformed.

_read_http_rst_stream(size, kind, flag)[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
  • size (int) – length of packet data

  • kind (int) – packet type

  • flag (str) – packet flags (8 bits)

Returns

Parsed packet data.

Return type

DataType_HTTPv2_RST_STREAM

Raises

ProtocolError – If the packet is malformed.

_read_http_settings(size, kind, flag)[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
  • size (int) – length of packet data

  • kind (int) – packet type

  • flag (str) – packet flags (8 bits)

Returns

Parsed packet data.

Return type

DataType_HTTPv2_SETTINGS

Raises

ProtocolError – If the packet is malformed.

_read_http_window_update(size, kind, flag)[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
  • size (int) – length of packet data

  • kind (int) – packet type

  • flag (str) – packet flags (8 bits)

Returns

Parsed packet data.

Return type

DataType_HTTPv2_WINDOW_UPDATE

Raises

ProtocolError – If the packet is malformed.

classmethod id()[source]

Index ID of the protocol.

Returns

Index ID of the protocol.

Return type

Literal[‘HTTPv2’]

make(**kwargs)[source]

Make (construct) packet data.

Keyword Arguments

**kwargs – Arbitrary keyword arguments.

Returns

Constructed packet data.

Return type

bytes

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.

Keyword Arguments

**kwargs – Arbitrary keyword arguments.

Returns

Parsed packet data.

Return type

DataType_HTTPv2

Raises

ProtocolError – If the packet is malformed.

property alias

Acronym of current protocol.

Return type

Literal[‘HTTP/2’]

pcapkit.protocols.application.httpv2._HTTP_FUNC: Dict[int, Callable[[pcapkit.protocols.application.httpv2.HTTPv2, int, int, str], DataType_HTTPv2_Frame]]

Process method for HTTP/2 packets.

Code

Method

Description

N/A

_read_http_none()

Unsigned

0x00

_read_http_data()

DATA

0x01

_read_http_headers()

HEADERS

0x02

_read_http_priority()

PRIORITY

0x03

_read_http_rst_stream()

RST_STREAM

0x04

_read_http_settings()

SETTINGS

0x05

_read_http_push_promise()

PUSH_PROMISE

0x06

_read_http_ping()

PING

0x07

_read_http_goaway()

GOAWAY

0x08

_read_http_window_update()

WINDOW_UPDATE

0x09

_read_http_continuation()

CONTINUATION

Data Structure

Important

Following classes are only for documentation purpose. They do NOT exist in the pcapkit module.

class pcapkit.protocols.application.httpv2.DataType_HTTPv2
Bases

TypedDict

Structure of HTTP/2 packet [RFC 7540].

length: int

Length.

type: pcapkit.const.http.frame.Frame

Type.

sid: int

Stream identifier.

packet: bytes

Raw packet data.

class pcapkit.protocols.application.httpv2.DataType_HTTPv2_Frame
Bases

TypedDict

HTTP/2 packet data.

HTTP/2 Unassigned Frame

class pcapkit.protocols.application.httpv2.DataType_HTTPv2_Unassigned
Bases

DataType_HTTPv2_Frame

flags: Literal[None]

HTTP/2 packet flags.

payload: Optional[types]

Raw packet payload.

HTTP/2 DATA Frame

For HTTP/2 DATA frame as described in RFC 7540, its structure is described as below:

Octets

Bits

Name

Description

0

0

http.length

Length

3

24

http.type

Type (0)

4

32

http.flags

Flags

5

40

Reserved

5

41

http.sid

Stream Identifier

9

72

http.pad_len

Pad Length (Optional)

10

80

http.data

Data

?

?

Padding (Optional)


class pcapkit.protocols.application.httpv2.DataType_HTTPv2_DATA
Bases

DataType_HTTPv2_Frame

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

flags: DataType_HTTPv2_DATA_Flags

HTTP/2 packet flags.

data: bytes

HTTP/2 transferred data.

class pcapkit.protocols.application.httpv2.DataType_HTTPv2_DATA_Flags
Bases

TypedDict

HTTP/2 DATA frame packet flags.

END_STREAM: bool
Bit

0

PADDED: bool
Bit

3

HTTP/2 HEADERS Frame

For HTTP/2 HEADERS frame as described in RFC 7540, its structure is described as below:

Octets

Bits

Name

Description

0

0

http.length

Length

3

24

http.type

Type (1)

4

32

http.flags

Flags

5

40

Reserved

5

41

http.sid

Stream Identifier

9

72

http.pad_len

Pad Length (Optional)

10

80

http.exclusive

Exclusive Flag

10

81

http.deps

Stream Dependency (Optional)

14

112

http.weight

Weight (Optional)

15

120

http.frag

Header Block Fragment

?

?

Padding (Optional)


class pcapkit.protocols.application.httpv2.DataType_HTTPv2_HEADERS
Bases

DataType_HTTPv2_Frame

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

flags: DataType_HTTPv2_HEADERS_Flags

HTTP/2 packet flags.

frag: Optional[bytes]

Header block fragment.

pad_len: int

Pad length.

exclusive: bool

Exclusive flag.

deps: int

Stream dependency.

weight: int

Weight.

class pcapkit.protocols.application.httpv2.DataType_HTTPv2_HEADERS_Flags
Bases

TypedDict

HTTP/2 HEADERS frame packet flags.

END_STREAM: bool
Bit

0

END_HEADERS: bool
Bit

2

PADDED: bool
Bit

3

PRIORITY: bool
Bit

5

HTTP/2 PRIORITY Frame

For HTTP/2 PRIORITY frame as described in RFC 7540, its structure is described as below:

Octets

Bits

Name

Description

0

0

http.length

Length

3

24

http.type

Type (2)

4

32

http.flags

Flags

5

40

Reserved

5

41

http.sid

Stream Identifier

9

72

http.exclusive

Exclusive Flag

9

73

http.deps

Stream Dependency

13

104

http.weight

Weight


class pcapkit.protocols.application.httpv2.DataType_HTTPv2_PRIORITY
Bases

DataType_HTTPv2_Frame

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

flags: Literal[None]

HTTP/2 packet flags.

exclusive: bool

Exclusive flag.

deps: int

Stream dependency.

weight: int

Weight.

HTTP/2 RST_STREAM Frame

For HTTP/2 RST_STREAM frame as described in RFC 7540, its structure is described as below:

Octets

Bits

Name

Description

0

0

http.length

Length

3

24

http.type

Type (3)

4

32

http.flags

Flags

5

40

Reserved

5

41

http.sid

Stream Identifier

9

72

http.error

Error Code


class pcapkit.protocols.application.httpv2.DataType_HTTPv2_RST_STREAM
Bases

DataType_HTTPv2_Frame

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

flags: Literal[None]

HTTP/2 packet flags.

error: pcapkit.const.http.error_code.ErrorCode

Error code.

HTTP/2 SETTINGS Frame

For HTTP/2 SETTINGS frame as described in RFC 7540, its structure is described as below:

Octets

Bits

Name

Description

0

0

http.length

Length

3

24

http.type

Type (4)

4

32

http.flags

Flags

5

40

Reserved

5

41

http.sid

Stream Identifier

9

72

http.settings

Settings

9

72

http.settings.id

Identifier

10

80

http.settings.value

Value


class pcapkit.protocols.application.httpv2.DataType_HTTPv2_SETTINGS
Bases

DataType_HTTPv2_Frame

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

flags: DataType_HTTPv2_SETTINGS_Flags

HTTP/2 packet flags.

settings: Tuple[pcapkit.const.http.setting.Setting]

Array of HTTP/2 settings.

class pcapkit.protocols.application.httpv2.DataType_HTTPv2_SETTINGS_Flags
Bases

TypedDict

HTTP/2 packet flags.

ACK: bool
Bit

0

HTTP/2 PUSH_PROMISE Frame

For HTTP/2 PUSH_PROMISE frame as described in RFC 7540, its structure is described as below:

Octets

Bits

Name

Description

0

0

http.length

Length

3

24

http.type

Type (5)

4

32

http.flags

Flags

5

40

Reserved

5

41

http.sid

Stream Identifier

9

72

http.pad_len

Pad Length (Optional)

10

80

Reserved

10

81

http.pid

Promised Stream ID

14

112

http.frag

Header Block Fragment

?

?

Padding (Optional)


class pcapkit.protocols.application.httpv2.DataType_HTTPv2_PUSH_PROMISE
Bases

DataType_HTTPv2_Frame

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

flags: DataType_HTTPv2_PUSH_PROMISE_Flags

HTTP/2 packet flags.

pid: int

Promised stream ID.

frag: Optional[bytes]

Header block fragment.

pad_len: int

Pad length.

class pcapkit.protocols.application.httpv2.DataType_HTTPv2_PUSH_PROMISE_Flags
Bases

TypedDict

HTTP/2 packet flags.

END_HEADERS: bool
Bit

2

PADDED: bool
Bit

3

HTTP/2 PING Frame

For HTTP/2 PING frame as described in RFC 7540, its structure is described as below:

Octets

Bits

Name

Description

0

0

http.length

Length

3

24

http.type

Type (6)

4

32

http.flags

Flags

5

40

Reserved

5

41

http.sid

Stream Identifier

9

72

http.data

Opaque Data


class pcapkit.protocols.application.httpv2.DataType_HTTPv2_PING
Bases

DataType_HTTPv2_Frame

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

flags: DataType_HTTPv2_PING_Flags

HTTP/2 packet flags.

data: bytes

Opaque data.

class pcapkit.protocols.application.httpv2.DataType_HTTPv2_PING_Flags
Bases

TypedDict

HTTP/2 packet flags.

ACK: bool
Bit

0

HTTP/2 GOAWAY Frame

For HTTP/2 GOAWAY frame as described in RFC 7540, its structure is described as below:

Octets

Bits

Name

Description

0

0

http.length

Length

3

24

http.type

Type (7)

4

32

http.flags

Flags

5

40

Reserved

5

41

http.sid

Stream Identifier

9

72

Reserved

9

73

http.last_sid

Last Stream ID

13

104

http.error

Error Code

17

136

http.data

Additional Debug Data (Optional)


class pcapkit.protocols.application.httpv2.DataType_HTTPv2_GOAWAY
Bases

DataType_HTTPv2_Frame

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

flags: Literal[None]

HTTP/2 packet flags.

last_sid: int

Last stream ID.

error: pcapkit.const.http.error_code.ErrorCode

Error code.

data: Optional[None]

Additional debug data.

HTTP/2 WINDOW_UPDATE Frame

For HTTP/2 WINDOW_UPDATE frame as described in RFC 7540, its structure is described as below:

Octets

Bits

Name

Description

0

0

http.length

Length

3

24

http.type

Type (8)

4

32

http.flags

Flags

5

40

Reserved

5

41

http.sid

Stream Identifier

9

72

Reserved

9

73

http.window

Window Size Increment


class pcapkit.protocols.application.httpv2.DataType_HTTPv2_WINDOW_UPDATE
Bases

DataType_HTTPv2_Frame

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

flags: Literal[None]

HTTP/2 packet flags.

window: int

Window size increment.

HTTP/2 CONTINUATION Frame

For HTTP/2 CONTINUATION frame as described in RFC 7540, its structure is described as below:

Octets

Bits

Name

Description

0

0

http.length

Length

3

24

http.type

Type (9)

4

32

http.flags

Flags

5

40

Reserved

5

41

http.sid

Stream Identifier

9

73

http.frag

Header Block Fragment


class pcapkit.protocols.application.httpv2.DataType_HTTPv2_CONTINUATION
Bases

DataType_HTTPv2_Frame

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

flags: DataType_HTTPv2_CONTINUATION_Flags

HTTP/2 packet flags.

frag: bytes

Header block fragment.

class pcapkit.protocols.application.httpv2.DataType_HTTPv2_CONTINUATION_Flags
Bases

TypedDict

HTTP/2 packet flags.

END_HEADERS: bool
Bit

2


*

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