Skip to main content

Module parser

Module parser 

Source
Expand description

H2 frame parser (nom-based).

Decodes every RFC 9113 §6 frame type plus RFC 9218 PRIORITY_UPDATE and unknown extension frames; rejects malformed framing with the matching H2Error so the connection can react with GOAWAY / RST_STREAM. Mostly zero-allocation, with bounded Vec<u8> allocations on priority_update and a SETTINGS-list cap (cf. priority_update_frame and the SETTINGS allocation cap test). Frame-size invariants are enforced via ensure_frame_size!.

Structs§

Continuation
Continuation frames are handled inline during HEADERS parsing. The wire-level parser does not track connection state (whether the previous frame was HEADERS/PUSH_PROMISE with END_HEADERS=0), so standalone CONTINUATION is rejected at the h2 state-machine layer (handle_header_state): when a CONTINUATION frame header is observed while the state is H2State::Header (i.e. no header block is in progress) we emit GOAWAY(PROTOCOL_ERROR) per RFC 9113 §6.10.
Data
FrameHeader
GoAway
Headers
ParserError
Ping
Priority
PriorityUpdate
RFC 9218 §7.1 PRIORITY_UPDATE frame payload.
PushPromise
PushPromise is always rejected with PROTOCOL_ERROR at the wire layer. Sozu never announces SETTINGS_ENABLE_PUSH=1, and RFC 9113 §8.4 requires that a peer which has not enabled server push treat a received PUSH_PROMISE as a connection error of type PROTOCOL_ERROR. Rejecting in the parser is defence-in-depth: any future refactor of mux/h2.rs that forgets to call handle_push_promise_frame cannot silently accept push traffic. The struct is retained so the outer match in h2.rs still compiles, but push_promise_frame never constructs it.
RstStream
Setting
Settings
StreamDependency
WindowUpdate

Enums§

Frame
FrameType
H2Error
ParserErrorKind
PriorityPart

Constants§

FLAG_ACK
ACK flag on SETTINGS/PING (§6.5, §6.7)
FLAG_END_HEADERS
END_HEADERS flag — signals last header block fragment (§6.2, §6.10)
FLAG_END_STREAM
END_STREAM flag — signals last frame for this stream (§6.1, §6.2)
FLAG_PADDED
PADDED flag — indicates padding is present (§6.1, §6.2)
FLAG_PRIORITY
PRIORITY flag on HEADERS — stream dependency follows (§6.2)
FRAME_HEADER_SIZE
H2 frame header size in bytes (RFC 9113 §4.1)
GOAWAY_PAYLOAD_SIZE
MAX_SETTINGS_ENTRIES
Maximum SETTINGS entries accepted in a single SETTINGS frame.
PING_PAYLOAD_SIZE
PRIORITY_PAYLOAD_SIZE
PRIORITY_UPDATE_MAX_VALUE
Maximum length of the priority_field_value portion of a PRIORITY_UPDATE frame (RFC 9218 §7.1). The field is a Structured Field Item (RFC 8941): ASCII-only, intended for compact dictionary payloads such as u=3, i. 1024 bytes mirrors nghttp2’s NGHTTP2_MAX_PRIORITY_VALUE_LEN and the upper-bound the h2 Rust crate enforces, an order of magnitude tighter than SETTINGS_MAX_FRAME_SIZE — the attacker is denied a per-frame 16 KiB allocation primitive sized in single TCP segments.
PRIORITY_UPDATE_MIN_PAYLOAD
Minimum payload size for a PRIORITY_UPDATE frame (RFC 9218 §7.1): the 4-byte prioritized stream ID. The priority field value is allowed to be empty (defaults to the RFC 9218 §4 defaults).
RST_STREAM_PAYLOAD_SIZE
SETTINGS_COUNT
Number of settings entries we send in our SETTINGS frame
SETTINGS_ENABLE_CONNECT_PROTOCOL
SETTINGS_ENABLE_PUSH
SETTINGS_ENTRY_SIZE
SETTINGS_HEADER_TABLE_SIZE
SETTINGS_INITIAL_WINDOW_SIZE
SETTINGS_MAX_CONCURRENT_STREAMS
SETTINGS_MAX_FRAME_SIZE
SETTINGS_MAX_HEADER_LIST_SIZE
SETTINGS_NO_RFC7540_PRIORITIES
STREAM_ID_MASK
Mask to extract 31-bit stream ID, clearing the reserved MSB (RFC 9113 §4.1)
WINDOW_UPDATE_PAYLOAD_SIZE

Functions§

continuation_frame
data_frame
frame_body
frame_header
goaway_frame
headers_frame
ping_frame
preface
priority_frame
priority_update_frame
RFC 9218 §7.1 PRIORITY_UPDATE frame parser. Payload layout:
push_promise_frame
rst_stream_frame
settings_frame
unknown_frame
Silently consume the payload of a frame whose type byte is not recognised, per RFC 9113 §5.5 (“Implementations MUST ignore and discard frames of unknown type”). Previously covered RFC 9218 PRIORITY_UPDATE (type 0x10); PRIORITY_UPDATE is now parsed through priority_update_frame.
window_update_frame