Commit 57badad
net.http: add HTTP/2 frame codec (RFC 7540) (#27356)
* net.http: add HTTP/2 frame codec (RFC 7540) for HTTP/2
Add the HTTP/2 binary framing layer: encoders and decoders for all ten frame
types plus a fallthrough for unknown types. Like the HPACK PR, this is purely
additive (new files in the http module) and does not touch any existing
net.http code path; nothing calls it yet.
Included:
- H2FrameHeader parsing of the 9-byte header, ignoring the reserved bit.
- A H2Frame sum type with DATA, HEADERS, PRIORITY, RST_STREAM, SETTINGS,
PUSH_PROMISE, PING, GOAWAY, WINDOW_UPDATE, CONTINUATION, and an UnknownFrame
variant. Unknown frame types are preserved rather than rejected, as required
by RFC 7540 Section 4.1.
- h2_read_frame / h2_parse_frame decoders and an .encode() method, with PADDED
and PRIORITY handling for HEADERS/DATA/PUSH_PROMISE.
- Structural validation that maps to FRAME_SIZE_ERROR / PROTOCOL_ERROR at the
connection layer: fixed-size frames (PRIORITY, RST_STREAM, PING,
WINDOW_UPDATE), SETTINGS payload as a multiple of 6 with empty ACK, and the
stream-id rules (DATA/HEADERS/etc. non-zero; SETTINGS/PING/GOAWAY zero).
- H2ErrorCode enum (Section 7) and the SETTINGS identifier and frame
type/flag constants.
Tests cover an encode/decode round-trip for every frame type, the on-wire
header layout, reserved-bit masking, padding decode (including pad length
exceeding the frame), the priority section on HEADERS, unknown-frame
preservation and re-encoding, reading consecutive frames from one buffer, and
the structural validation errors above. Passes under -W -cstrict -cc clang.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* net.http: document deferred HTTP/2 semantic checks in frame codec
Add comments noting that PRIORITY self-dependency (RFC 7540 Section 5.3.1) and
zero WINDOW_UPDATE increments (Section 6.9) are intentionally not rejected by
the frame codec. Both are stream errors whose correct handling is RST_STREAM on
the affected stream (and, for a zero increment on stream 0, a connection
error). That stream-vs-connection distinction belongs to the connection layer,
which needs the decoded frame to respond; rejecting in the codec would turn a
recoverable stream error into a connection-fatal decode error.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Richard Wheeler <quaesitor.scientiam@gmail.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent c5fca67 commit 57badad
3 files changed
Lines changed: 869 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
0 commit comments