HPACK
The HPACK layer implements header compression per RFC 7541. An HPACKEncoder and HPACKDecoder each maintain a dynamic table of up to max_table_size bytes, sharing a statically-defined table of 61 common headers. PureHTTP2.jl's HPACK implementation is cross-validated in CI against the industry http2jp/hpack-test-case vector set (four independent producers — nghttp2, go-hpack, python-hpack, raw-data).
Encoder and decoder
PureHTTP2.HPACKEncoder — Type
HPACKEncoder(max_table_size::Int = 4096; use_huffman::Bool = false)HPACK encoder for compressing HTTP/2 headers (RFC 7541). Maintains a dynamic header table up to max_table_size bytes in size. When use_huffman=true, string literals are Huffman-encoded when doing so saves bytes.
Fields
dynamic_table::DynamicTable: Dynamic table for compressionuse_huffman::Bool: Whether to use Huffman encoding
Example
julia> using PureHTTP2
julia> encoder = HPACKEncoder();
julia> decoder = HPACKDecoder();
julia> headers = [(":method", "GET"), (":path", "/"), (":scheme", "https")];
julia> bytes = encode_headers(encoder, headers);
julia> decode_headers(decoder, bytes)
3-element Vector{Tuple{String, String}}:
(":method", "GET")
(":path", "/")
(":scheme", "https")PureHTTP2.HPACKDecoder — Type
HPACKDecoderHPACK decoder for decompressing HTTP/2 headers.
Fields
dynamic_table::DynamicTable: Dynamic table for decompression
PureHTTP2.encode_headers — Function
encode_headers(encoder::HPACKEncoder, headers::Vector{Tuple{String, String}}) -> Vector{UInt8}Encode a list of headers into an HPACK header block.
PureHTTP2.decode_headers — Function
decode_headers(decoder::HPACKDecoder, data::AbstractVector{UInt8}) -> Vector{Tuple{String, String}}Decode an HPACK header block into a list of headers.
PureHTTP2.set_max_table_size! — Function
set_max_table_size!(encoder::HPACKEncoder, size::Int)
set_max_table_size!(decoder::HPACKDecoder, size::Int)Update the maximum dynamic table size.
PureHTTP2.encode_table_size_update — Function
encode_table_size_update(new_size::Int) -> Vector{UInt8}Encode a dynamic table size update instruction.
Dynamic table
PureHTTP2.DynamicTable — Type
DynamicTableHPACK dynamic table for header compression.
Fields
entries::Vector{Tuple{String, String}}: Header entries (most recent first)size::Int: Current size in octetsmax_size::Int: Maximum size in octets
Low-level primitives
These helpers are exported for users who need to work at a level below the encoder/decoder — for example, an implementation building its own custom framing or needing to compute Huffman-encoded lengths before allocating.
PureHTTP2.huffman_encode — Function
huffman_encode(data::AbstractVector{UInt8}) -> Vector{UInt8}Encode data using Huffman encoding per RFC 7541 Appendix B. Returns the Huffman-encoded bytes with proper padding.
PureHTTP2.huffman_decode — Function
huffman_decode(data::AbstractVector{UInt8}) -> Vector{UInt8}Decode Huffman-encoded data per RFC 7541 Appendix B.
PureHTTP2.huffman_encoded_length — Function
huffman_encoded_length(data::AbstractVector{UInt8}) -> IntCalculate the length of Huffman-encoded data without actually encoding. Used to decide whether Huffman encoding saves space.
PureHTTP2.encode_integer — Function
encode_integer(value::Int, prefix_bits::Int) -> Vector{UInt8}Encode an integer using HPACK integer representation.
PureHTTP2.decode_integer — Function
decode_integer(bytes::AbstractVector{UInt8}, offset::Int, prefix_bits::Int) -> Tuple{Int, Int}Decode an HPACK integer starting at offset. Returns (value, new_offset).
PureHTTP2.encode_string — Function
encode_string(s::String; huffman::Bool=false) -> Vector{UInt8}Encode a string using HPACK string representation. Supports both raw and Huffman encoding per RFC 7541 Section 5.2.
When huffman=true, the string is Huffman-encoded if it saves space.
PureHTTP2.decode_string — Function
decode_string(bytes::AbstractVector{UInt8}, offset::Int) -> Tuple{String, Int}Decode an HPACK string starting at offset. Returns (string, new_offset). Supports both raw strings and Huffman-encoded strings per RFC 7541.