quic_qpack (quic v1.3.0)
View SourceQPACK header compression for HTTP/3 (RFC 9204).
This module provides QPACK encoding and decoding for HTTP/3 header compression. It supports both stateless (static table only) and stateful (with dynamic table) operation.
Quick Start
Stateless encoding/decoding (static table only):
Headers = [{<<":method">>, <<"GET">>}, {<<":path">>, <<"/">>}],
Encoded = quic_qpack:encode(Headers),
{ok, Headers} = quic_qpack:decode(Encoded).Stateful encoding with dynamic table:
State0 = quic_qpack:new(#{max_dynamic_size => 4096}),
{Encoded, State1} = quic_qpack:encode(Headers, State0),
{{ok, Headers}, State2} = quic_qpack:decode(Encoded, State1).
Summary
Functions
Clear pending encoder instructions after sending.
Decode QPACK-encoded headers (stateless).
Decode QPACK-encoded headers with state.
Encode headers using QPACK (stateless, static table only).
Encode headers using QPACK with state.
Encode headers with stream tracking for section acknowledgment. This variant tracks the RIC per stream for proper section_ack handling.
Encode an Insert Count Increment for the decoder stream.
Encode a Section Acknowledgment for the decoder stream. StreamId should be the stream where headers were decoded.
Encode a Stream Cancellation for the decoder stream. Used when a stream is cancelled before headers are fully decoded.
Get dynamic table capacity.
Get pending encoder instructions. These should be sent on the encoder stream.
Get current insert count.
Get known received count (acknowledged by decoder).
Get last Required Insert Count from encoding.
Initialize QPACK state (static-only mode).
Initialize QPACK state with options. Options: max_dynamic_size - Enable dynamic table with given max size (default: 0 = disabled)
Process decoder instructions from the peer's decoder stream. Updates known_received_count based on acknowledgments. Returns {ok, State} when all data is processed, {incomplete, RemainingData, State} when more data is needed, or {error, Reason} on error.
Process encoder instructions from the peer's encoder stream. Updates the dynamic table based on received instructions. Returns {ok, State} when all data is processed, {incomplete, RemainingData, State} when more data is needed, or {error, Reason} on error.
Set dynamic table capacity. This generates a Set Dynamic Table Capacity instruction for the encoder stream. RFC 9204 §4.3: the capacity MUST NOT exceed the peer-advertised maximum (max_allowed_capacity). Values above the max are clamped to the max so callers cannot produce a non-conformant instruction.
Types
Functions
Clear pending encoder instructions after sending.
Decode QPACK-encoded headers (stateless).
-spec decode(binary(), state()) -> {{ok, headers()} | {blocked, non_neg_integer()} | {error, term()}, state()}.
Decode QPACK-encoded headers with state.
Encode headers using QPACK (stateless, static table only).
Encode headers using QPACK with state.
-spec encode(headers(), non_neg_integer(), state()) -> {binary(), state()}.
Encode headers with stream tracking for section acknowledgment. This variant tracks the RIC per stream for proper section_ack handling.
-spec encode_insert_count_increment(non_neg_integer()) -> binary().
Encode an Insert Count Increment for the decoder stream.
-spec encode_section_ack(non_neg_integer()) -> binary().
Encode a Section Acknowledgment for the decoder stream. StreamId should be the stream where headers were decoded.
-spec encode_stream_cancel(non_neg_integer()) -> binary().
Encode a Stream Cancellation for the decoder stream. Used when a stream is cancelled before headers are fully decoded.
-spec get_dynamic_capacity(state()) -> non_neg_integer().
Get dynamic table capacity.
Get pending encoder instructions. These should be sent on the encoder stream.
-spec get_insert_count(state()) -> non_neg_integer().
Get current insert count.
-spec get_known_received_count(state()) -> non_neg_integer().
Get known received count (acknowledged by decoder).
-spec get_last_ric(state()) -> non_neg_integer().
Get last Required Insert Count from encoding.
-spec new() -> state().
Initialize QPACK state (static-only mode).
Initialize QPACK state with options. Options: max_dynamic_size - Enable dynamic table with given max size (default: 0 = disabled)
-spec process_decoder_instructions(binary(), state()) -> {ok, state()} | {incomplete, binary(), state()} | {error, term()}.
Process decoder instructions from the peer's decoder stream. Updates known_received_count based on acknowledgments. Returns {ok, State} when all data is processed, {incomplete, RemainingData, State} when more data is needed, or {error, Reason} on error.
-spec process_encoder_instructions(binary(), state()) -> {ok, state()} | {incomplete, binary(), state()} | {error, term()}.
Process encoder instructions from the peer's encoder stream. Updates the dynamic table based on received instructions. Returns {ok, State} when all data is processed, {incomplete, RemainingData, State} when more data is needed, or {error, Reason} on error.
-spec set_dynamic_capacity(non_neg_integer(), state()) -> state().
Set dynamic table capacity. This generates a Set Dynamic Table Capacity instruction for the encoder stream. RFC 9204 §4.3: the capacity MUST NOT exceed the peer-advertised maximum (max_allowed_capacity). Values above the max are clamped to the max so callers cannot produce a non-conformant instruction.