quic_qpack (quic v1.3.0)

View Source

QPACK 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

header/0

-type header() :: {Name :: binary(), Value :: binary()}.

headers/0

-type headers() :: [header()].

state/0

-opaque state()

Functions

clear_encoder_instructions(State)

-spec clear_encoder_instructions(state()) -> state().

Clear pending encoder instructions after sending.

decode(Data)

-spec decode(binary()) -> {ok, headers()} | {error, term()}.

Decode QPACK-encoded headers (stateless).

decode(Data, State)

-spec decode(binary(), state()) ->
                {{ok, headers()} | {blocked, non_neg_integer()} | {error, term()}, state()}.

Decode QPACK-encoded headers with state.

encode(Headers)

-spec encode(headers()) -> binary().

Encode headers using QPACK (stateless, static table only).

encode(Headers, State)

-spec encode(headers(), state()) -> {binary(), state()}.

Encode headers using QPACK with state.

encode(Headers, StreamId, 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.

encode_insert_count_increment(Increment)

-spec encode_insert_count_increment(non_neg_integer()) -> binary().

Encode an Insert Count Increment for the decoder stream.

encode_section_ack(StreamId)

-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.

encode_stream_cancel(StreamId)

-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.

get_dynamic_capacity(Qpack)

-spec get_dynamic_capacity(state()) -> non_neg_integer().

Get dynamic table capacity.

get_encoder_instructions(Qpack)

-spec get_encoder_instructions(state()) -> binary().

Get pending encoder instructions. These should be sent on the encoder stream.

get_insert_count(Qpack)

-spec get_insert_count(state()) -> non_neg_integer().

Get current insert count.

get_known_received_count(Qpack)

-spec get_known_received_count(state()) -> non_neg_integer().

Get known received count (acknowledged by decoder).

get_last_ric(Qpack)

-spec get_last_ric(state()) -> non_neg_integer().

Get last Required Insert Count from encoding.

new()

-spec new() -> state().

Initialize QPACK state (static-only mode).

new(Opts)

-spec new(#{atom() => term()}) -> state().

Initialize QPACK state with options. Options: max_dynamic_size - Enable dynamic table with given max size (default: 0 = disabled)

process_decoder_instructions(Data, State)

-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.

process_encoder_instructions(Data, State)

-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.

set_dynamic_capacity(Capacity, Qpack)

-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.