http.h2.frames
import http
httpexposes this ashttp.h2.frames, soimport httpis enough and the names are called ashttp.h2.frames.*.import http.h2.framesreaches the same definitions directly.
The HTTP/2 frame layer (RFC 9113 §4 and §6): a nine-octet header - a 24-bit length, a type, a flags byte, and a 31-bit stream identifier - followed by a payload.
Constants
PREFACE
http.h2.frames.PREFACE: string = 'PRI * HTTP/2.0
SM
'
The connection preface every HTTP/2 client sends before anything else. A
server that reads these exact bytes knows it is speaking HTTP/2 and not
an HTTP/1.1 request that happens to start with PRI.
DATA
http.h2.frames.DATA = 0
DATA frame. @type int
HEADERS
http.h2.frames.HEADERS = 1
HEADERS frame. @type int
PRIORITY
http.h2.frames.PRIORITY = 2
PRIORITY frame; deprecated by RFC 9113 and ignored here. @type int
RST_STREAM
http.h2.frames.RST_STREAM = 3
RST_STREAM frame. @type int
SETTINGS
http.h2.frames.SETTINGS = 4
SETTINGS frame. @type int
PUSH_PROMISE
http.h2.frames.PUSH_PROMISE = 5
PUSH_PROMISE frame. @type int
PING
http.h2.frames.PING = 6
PING frame. @type int
GOAWAY
http.h2.frames.GOAWAY = 7
GOAWAY frame. @type int
WINDOW_UPDATE
http.h2.frames.WINDOW_UPDATE = 8
WINDOW_UPDATE frame. @type int
CONTINUATION
http.h2.frames.CONTINUATION = 9
CONTINUATION frame. @type int
FLAG_END_STREAM
http.h2.frames.FLAG_END_STREAM = 1
END_STREAM flag, on DATA and HEADERS. @type int
FLAG_ACK
http.h2.frames.FLAG_ACK = 1
ACK flag, on SETTINGS and PING. @type int
FLAG_END_HEADERS
http.h2.frames.FLAG_END_HEADERS = 4
END_HEADERS flag, on HEADERS, PUSH_PROMISE and CONTINUATION. @type int
FLAG_PADDED
http.h2.frames.FLAG_PADDED = 8
PADDED flag, on DATA, HEADERS and PUSH_PROMISE. @type int
FLAG_PRIORITY
http.h2.frames.FLAG_PRIORITY = 32
PRIORITY flag, on HEADERS. @type int
SETTINGS_HEADER_TABLE_SIZE
http.h2.frames.SETTINGS_HEADER_TABLE_SIZE = 1
SETTINGS_HEADER_TABLE_SIZE. @type int
SETTINGS_ENABLE_PUSH
http.h2.frames.SETTINGS_ENABLE_PUSH = 2
SETTINGS_ENABLE_PUSH. @type int
SETTINGS_MAX_CONCURRENT_STREAMS
http.h2.frames.SETTINGS_MAX_CONCURRENT_STREAMS = 3
SETTINGS_MAX_CONCURRENT_STREAMS. @type int
SETTINGS_INITIAL_WINDOW_SIZE
http.h2.frames.SETTINGS_INITIAL_WINDOW_SIZE = 4
SETTINGS_INITIAL_WINDOW_SIZE. @type int
SETTINGS_MAX_FRAME_SIZE
http.h2.frames.SETTINGS_MAX_FRAME_SIZE = 5
SETTINGS_MAX_FRAME_SIZE. @type int
SETTINGS_MAX_HEADER_LIST_SIZE
http.h2.frames.SETTINGS_MAX_HEADER_LIST_SIZE = 6
SETTINGS_MAX_HEADER_LIST_SIZE. @type int
NO_ERROR
http.h2.frames.NO_ERROR = 0
NO_ERROR. @type int
PROTOCOL_ERROR
http.h2.frames.PROTOCOL_ERROR = 1
PROTOCOL_ERROR. @type int
INTERNAL_ERROR
http.h2.frames.INTERNAL_ERROR = 2
INTERNAL_ERROR. @type int
FLOW_CONTROL_ERROR
http.h2.frames.FLOW_CONTROL_ERROR = 3
FLOW_CONTROL_ERROR. @type int
SETTINGS_TIMEOUT
http.h2.frames.SETTINGS_TIMEOUT = 4
SETTINGS_TIMEOUT. @type int
STREAM_CLOSED
http.h2.frames.STREAM_CLOSED = 5
STREAM_CLOSED. @type int
FRAME_SIZE_ERROR
http.h2.frames.FRAME_SIZE_ERROR = 6
FRAME_SIZE_ERROR. @type int
REFUSED_STREAM
http.h2.frames.REFUSED_STREAM = 7
REFUSED_STREAM. @type int
CANCEL
http.h2.frames.CANCEL = 8
CANCEL. @type int
COMPRESSION_ERROR
http.h2.frames.COMPRESSION_ERROR = 9
COMPRESSION_ERROR. @type int
CONNECT_ERROR
http.h2.frames.CONNECT_ERROR = 10
CONNECT_ERROR. @type int
ENHANCE_YOUR_CALM
http.h2.frames.ENHANCE_YOUR_CALM = 11
ENHANCE_YOUR_CALM. @type int
INADEQUATE_SECURITY
http.h2.frames.INADEQUATE_SECURITY = 12
INADEQUATE_SECURITY. @type int
HTTP_1_1_REQUIRED
http.h2.frames.HTTP_1_1_REQUIRED = 13
HTTP_1_1_REQUIRED. @type int
Functions
read_u32()
http.h2.frames.read_u32(data, offset: number) -> number
Reads a 32-bit big-endian integer from data at offset.
Parameters
data(bytes)offset(number)
Returns number
write_u32()
http.h2.frames.write_u32(out, value: number)
Appends a 32-bit big-endian integer to out.
Parameters
out(bytes)value(number)
read_u24()
http.h2.frames.read_u24(data, offset: number) -> number
Reads a 24-bit big-endian integer from data at offset.
Parameters
data(bytes)offset(number)
Returns number
read_frame()
http.h2.frames.read_frame(connection, max_frame_size: number) -> Frame
Reads one frame off a connection.
Padding is stripped here, so a caller never has to think about it, and a pad length that does not fit inside the frame is rejected - that mismatch is a connection error, not a frame to salvage.
Parameters
connection(Connection)max_frame_size(number) — refuse anything larger
Returns Frame
Raises ProtocolError on a malformed or over-large frame
write_frame()
http.h2.frames.write_frame(connection, type: int, flags: int, stream_id: int, payload)
Writes one frame to a connection.
Parameters
connection(Connection)type(int)flags(int)stream_id(int)payload(?bytes)
encode_settings()
http.h2.frames.encode_settings(values: dict) -> bytes
Builds a SETTINGS payload from a dictionary of identifier to value.
Parameters
values(dict)
Returns bytes
decode_settings()
http.h2.frames.decode_settings(payload) -> dict
Parses a SETTINGS payload into a dictionary.
Unknown identifiers are kept rather than dropped - an endpoint must ignore settings it does not understand, and keeping them makes that the caller’s decision rather than a silent one here.
Parameters
payload(bytes)
Returns dict
Raises ProtocolError if the payload is not a whole number of
six-octet entries
encode_goaway()
http.h2.frames.encode_goaway(last_stream_id: int, error_code: int, debug_message: ?string) -> bytes
Builds a GOAWAY payload.
Parameters
last_stream_id(int) — the highest stream this endpoint acted onerror_code(int)debug_message(?string) — for humans reading a packet capture; never interpreted by the peer
Returns bytes
encode_error()
http.h2.frames.encode_error(error_code: int) -> bytes
Builds an RST_STREAM payload.
Parameters
error_code(int)
Returns bytes
Classes
Frame
class http.h2.frames.Frame
One frame, as read off the wire.
- printable — has a
@to_string(), soechoandprint()show something useful
Fields
| Field | Type | Description |
|---|---|---|
type | int | The frame type - one of the constants above. |
flags | int | The flags byte. |
stream_id | int | The stream this frame belongs to; 0 for connection-level frames. |
payload | bytes | The payload, with any padding already removed. |
Constructor
http.h2.frames.Frame(type, flags, stream_id, payload)
Frame.has_flag()
http.h2.frames.Frame.has_flag(flag: int) -> bool
Whether flag is set.
Parameters
flag(int)
Returns bool
Frame.to_string()
http.h2.frames.Frame.to_string()
2026, Richard Ore and Zuri contributors