Summary#
Implement HPACK (RFC 7541), the header compression format used by HTTP/2. This is a prerequisite for HTTP/2 framing.
Background#
HTTP/2 compresses headers using HPACK, which combines a static table of common headers, a dynamic table of recently-seen headers, and Huffman coding for string literals. This dramatically reduces header overhead compared to HTTP/1.1's plaintext headers.
Acceptance Criteria#
- Static table: the 61 predefined header name/value pairs from RFC 7541 Appendix A
- Dynamic table: FIFO ring buffer of recently encoded/decoded headers with configurable max size
- Huffman encoder/decoder: the fixed Huffman code from RFC 7541 Appendix B
- Header encoding (for requests):
- Indexed header field (reference static or dynamic table)
- Literal header with incremental indexing (add to dynamic table)
- Literal header without indexing
- Literal header never indexed (sensitive headers like cookies)
- Dynamic table size update
- Header decoding (for responses):
- Decode all representation types
- Maintain decoder dynamic table in sync with encoder
- Handle dynamic table size updates from SETTINGS frames
- Integer encoding/decoding: HPACK integer representation with prefix bits (RFC 7541 §5.1)
- All operations are pure Rust, no external dependencies
- Comprehensive tests against RFC 7541 examples (Appendix C)
- Add module at
crates/net/src/http2/hpack.rs
Implementation Notes#
- The static table is a const array — no allocation needed
- Dynamic table is bounded by
SETTINGS_HEADER_TABLE_SIZE(default 4096 bytes) - Entry size = name length + value length + 32 (overhead per RFC 7541 §4.1)
- Huffman tree can be implemented as a lookup table for decoding (256-entry decode table)
- For encoding, a simple table mapping byte → (code, bit_length) suffices
- This module should be self-contained with a clean encode/decode API
Dependencies#
None — can be developed independently.
Phase#
Phase 15: Performance