Skip to content

Comments

feat: HTTP/2 Frame Parser - All Frame Types (TASK-203)#89

Merged
copyleftdev merged 2 commits intomainfrom
feat/TASK-203-http2-frame-parser
Jan 11, 2026
Merged

feat: HTTP/2 Frame Parser - All Frame Types (TASK-203)#89
copyleftdev merged 2 commits intomainfrom
feat/TASK-203-http2-frame-parser

Conversation

@copyleftdev
Copy link
Owner

@copyleftdev copyleftdev commented Nov 3, 2025

Problem

Need HTTP/2 frame parsing per RFC 7540 for HTTP/2 load testing support.

Refs #62

Solution

Implemented complete HTTP/2 frame parser with all RFC 7540 frame types and comprehensive validation.

Features Implemented ✅

Frame Parsing:

  • Frame header parsing (9 bytes: length, type, flags, stream ID)
  • Complete frame parsing with payload extraction
  • Big-endian integer parsing (24-bit length, 31-bit stream ID)
  • Frame type enum with 10 types (RFC 7540)

Frame Types (ALL Implemented):

  • SETTINGS frame parsing (connection parameters, Section 6.5)
  • DATA frame parsing (stream data with padding support, Section 6.1)
  • PING frame parsing (8-byte opaque data, Section 6.7)
  • PRIORITY frame parsing (stream prioritization, Section 6.3)
  • RST_STREAM frame parsing (stream termination with error code, Section 6.4)
  • GOAWAY frame parsing (graceful connection shutdown, Section 6.8)
  • WINDOW_UPDATE frame parsing (flow control updates, Section 6.9)
  • HEADERS frame parsing (request/response headers, Section 6.2)
  • CONTINUATION frame parsing (header block continuation, Section 6.10)

Validation:

  • Frame size limits (default 16KB, max 16MB per spec)
  • Stream ID validation per frame type
  • Protocol error detection for violations
  • Connection preface validation (24-byte magic string)
  • Flow control error for zero WINDOW_UPDATE increment

Error Handling:

  • FrameTooShort: Incomplete frame data
  • FrameTooLarge: Exceeds max frame size
  • InvalidFrameType: Unknown frame type byte
  • InvalidStreamId: Wrong stream ID for frame type
  • ProtocolError: HTTP/2 protocol violation
  • FlowControlError: Flow control error (e.g., zero window increment)

Supporting Types:

  • ErrorCode enum with all RFC 7540 Section 7 error codes
  • PriorityPayload (exclusive bit, stream dependency, weight)
  • GoawayPayload (last stream ID, error code, debug data)
  • HeadersPayload (priority, header block fragment, end_stream, end_headers)
  • ContinuationPayload (header block fragment, end_headers)

Tiger Style Compliance ✓

All functions have assertions for internal invariants:

  • Precondition: caller must pass correct frame type
  • Postcondition: result slices are within bounds

All loops bounded:

  • SETTINGS parameter parsing (max 100 parameters)

Testing

19 comprehensive unit tests covering:

  1. ✅ Frame header parsing (9 bytes)
  2. ✅ SETTINGS frame with parameters
  3. ✅ DATA frame with payload
  4. ✅ PING frame with opaque data
  5. ✅ PRIORITY frame parsing
  6. ✅ RST_STREAM frame parsing
  7. ✅ GOAWAY frame parsing
  8. ✅ WINDOW_UPDATE frame parsing
  9. ✅ WINDOW_UPDATE zero increment error (FlowControlError)
  10. ✅ HEADERS frame basic (no priority)
  11. ✅ HEADERS frame with PRIORITY flag
  12. ✅ CONTINUATION frame parsing
  13. ✅ Frame size limit enforcement
  14. ✅ Invalid stream ID rejection for SETTINGS
  15. ✅ Reject DATA frame on stream 0
  16. ✅ Connection preface validation
  17. ✅ Error codes enum values
  18. ✅ Tiger Style assertion compliance
  19. ✅ Bounded loops verification

All 19 HTTP/2 frame tests passing ✅

Acceptance Criteria Status

  • Parse HTTP/2 frame header (9 bytes) ✅
  • Parse frame types: DATA, SETTINGS, PING ✅
  • Parse frame types: HEADERS, PRIORITY, RST_STREAM, GOAWAY, WINDOW_UPDATE, CONTINUATION ✅
  • HPACK decoder (static + dynamic table) ⚠️ Deferred
  • Flow control tracking (stream + connection level) ⚠️ Deferred
  • Error detection: ProtocolError, FlowControlError, etc. ✅
  • Frame size limits (16 MB max per spec) ✅
  • Minimum 2 assertions per function ✅
  • All tests pass ✅
  • Fuzz test: 1M inputs per frame type, zero crashes ⚠️ Future PR

Status: All frame type parsers complete. HPACK decoding and flow control tracking deferred.

Implementation Notes

HEADERS Frame:

  • Returns raw header block fragment (HPACK decoding needed separately)
  • Supports PADDED flag for padding
  • Supports PRIORITY flag for embedded priority data
  • Extracts END_STREAM and END_HEADERS flags

Assertion Pattern:

  • Use std.debug.assert() for caller errors (wrong frame type passed)
  • Use error returns for external data validation (malformed frames)

Files

Modified:

  • src/http2_frame.zig - All frame type parsers (+~250 lines)
  • src/z6.zig - Export new types (ErrorCode, HeadersPayload, etc.)
  • tests/unit/http2_frame_test.zig - 19 tests (+~200 lines)

What's NOT Yet Implemented ⚠️

Deferred to follow-up PRs:

  • ❌ HPACK header compression/decompression (RFC 7541)
  • ❌ Stream state machine
  • ❌ Flow control tracking
  • ❌ Fuzz testing (1M inputs per frame type)

What This Enables

  • Complete HTTP/2 frame parsing for all frame types
  • Foundation for HTTP/2 handler implementation
  • Ready for HPACK decoder integration
  • Protocol validation and error detection

Next Steps (Future PRs)

  1. HPACK header compression/decompression (RFC 7541)
  2. Stream state machine
  3. Flow control tracking
  4. Fuzz testing (1M inputs per frame type)
  5. HTTP/2 handler (similar to HTTP1Handler)

Checklist

  • All 19 tests passing
  • Tiger Style compliance (assertions, bounds, errors)
  • Code formatted with zig fmt
  • RFC 7540 section references in comments
  • No silent failures
  • All loops bounded

🐅 Generated with Claude Code

copyleftdev and others added 2 commits January 10, 2026 21:55
Implements foundational HTTP/2 frame parsing per RFC 7540.

**Frame Parsing:**
- Frame header parsing (9 bytes: length, type, flags, stream ID)
- Complete frame parsing with payload
- Frame types: SETTINGS, DATA, PING (core set)
- Connection preface validation

**Frame Validation:**
- Frame size limits (default 16KB, max 16MB)
- Stream ID validation per frame type
- Protocol error detection
- Padding handling for DATA frames

**Tiger Style Compliance:**
- All functions have ≥2 assertions ✓
- All loops bounded (max 100 settings parameters) ✓
- Explicit error handling ✓
- No silent failures ✓

- FrameTooShort: Incomplete frame data
- FrameTooLarge: Exceeds max frame size
- InvalidFrameType: Unknown frame type
- InvalidStreamId: Wrong stream ID for frame type
- ProtocolError: HTTP/2 protocol violation
- FlowControlError: Flow control violation

**Frame Header Format:**
- Length: 24 bits (big-endian)
- Type: 8 bits (enum)
- Flags: 8 bits
- Stream ID: 31 bits (big-endian, R bit ignored)

**Frame Types (Core):**
- SETTINGS (0x04): Connection parameters
- DATA (0x00): Stream data with optional padding
- PING (0x06): Connection liveness check

**Validation Rules:**
- SETTINGS frames MUST have stream ID 0
- DATA frames MUST NOT have stream ID 0
- PING frames MUST have stream ID 0
- PING payload MUST be exactly 8 bytes
- SETTINGS payload MUST be multiple of 6 bytes

8 comprehensive unit tests:
1. ✅ Frame header parsing
2. ✅ SETTINGS frame with parameters
3. ✅ DATA frame with payload
4. ✅ PING frame with opaque data
5. ✅ Frame size limit validation
6. ✅ Invalid stream ID rejection
7. ✅ Connection preface validation
8. ✅ Tiger Style assertion compliance

Build Summary: 38/41 steps succeeded
201/201 tests passed ✅ (+8 HTTP/2 frame tests)

- ❌ HEADERS frame parsing
- ❌ HPACK header compression/decompression
- ❌ PRIORITY, RST_STREAM, GOAWAY, WINDOW_UPDATE, CONTINUATION frames
- ❌ Stream state machine
- ❌ Flow control tracking
- ❌ Fuzz testing (1M inputs per frame type)

These will be added in follow-up work to keep the implementation incremental.

**New:**
- src/http2_frame.zig (332 lines) - Frame parser
- tests/unit/http2_frame_test.zig (162 lines) - Unit tests

**Modified:**
- src/z6.zig - Export HTTP/2 frame types
- build.zig - Add HTTP/2 frame tests

**Total:** +494 lines

This provides a solid foundation for HTTP/2 support with core frame parsing.
Full HTTP/2 implementation will build incrementally on this base.

Refs #62
Implement parsing for all RFC 7540 frame types:
- PRIORITY: stream prioritization (Section 6.3)
- RST_STREAM: stream termination with error code (Section 6.4)
- GOAWAY: graceful connection shutdown (Section 6.8)
- WINDOW_UPDATE: flow control updates (Section 6.9)
- HEADERS: request/response headers (Section 6.2)
- CONTINUATION: header block continuation (Section 6.10)

Add supporting types:
- PriorityPayload, GoawayPayload, HeadersPayload, ContinuationPayload
- ErrorCode enum with all RFC 7540 Section 7 error codes

Fix assertion pattern for external input validation:
- Keep assertions for internal invariants (caller errors)
- Use error returns for external data validation

Note: HPACK decoding deferred - returns raw header block fragments.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@copyleftdev copyleftdev force-pushed the feat/TASK-203-http2-frame-parser branch from 30200a4 to 6b8a649 Compare January 11, 2026 06:05
@copyleftdev copyleftdev changed the title feat: HTTP/2 Frame Parser - Core Implementation (TASK-203) [WIP] feat: HTTP/2 Frame Parser - All Frame Types (TASK-203) Jan 11, 2026
@copyleftdev copyleftdev marked this pull request as ready for review January 11, 2026 06:08
@copyleftdev copyleftdev merged commit af08b88 into main Jan 11, 2026
1 check passed
@copyleftdev copyleftdev deleted the feat/TASK-203-http2-frame-parser branch January 11, 2026 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant