nhttp_qpack (nhttp_lib v1.0.0)

View Source

QPACK header compression for HTTP/3 (RFC 9204).

Public API facade that delegates to the encoder and decoder state machines. Provides a symmetric interface for encoding and decoding field sections on request/push streams, and feeding control stream data in both directions.

Encoder usage

{ok, Enc0} = nhttp_qpack:new_encoder(#{
    max_table_capacity => 4096,
    max_blocked_streams => 100
}),
Headers = [{<<":method">>, <<"GET">>}, {<<":path">>, <<"/">>}],
{ok, Enc1, EncStreamData, FieldData} =
    nhttp_qpack:encode_field_section(Enc0, 0, Headers).

Decoder usage

{ok, Dec0} = nhttp_qpack:new_decoder(#{
    max_table_capacity => 4096,
    max_blocked_streams => 100
}),
{ok, Dec1, DecStreamData, FieldLines} =
    nhttp_qpack:decode_field_section(Dec0, 0, FieldData).

Summary

Functions

Decode an encoded field section from a request or push stream. Returns {ok, Decoder, DecoderStreamData, FieldLines} on success, {blocked, Decoder} when the field section references entries not yet received on the encoder stream, or {error, Reason} on failure.

Encode a field section for the given stream.

Feed decoder stream data into the encoder. Processes section acknowledgments, stream cancellations, and insert count increments from the decoder.

Feed encoder stream data into the decoder. Processes encoder instructions (table insertions, capacity changes, duplications) and unblocks any streams whose required insert count is now satisfied. Returns {ok, Decoder, UnblockedResults} where UnblockedResults is a list of {StreamId, DecoderStreamData, FieldLines} tuples for streams that became unblocked.

Create a new QPACK decoder.

Create a new QPACK encoder.

Reconcile the encoder against the peer's advertised QPACK limits (SETTINGS_QPACK_MAX_TABLE_CAPACITY and SETTINGS_QPACK_BLOCKED_STREAMS). Call once when the peer's HTTP/3 SETTINGS are received. See nhttp_qpack_encoder:reconcile_peer_limits/3.

Types

decoder()

-type decoder() :: nhttp_qpack_decoder:state().

decoder_config()

-type decoder_config() :: nhttp_qpack_decoder:config().

encoder()

-type encoder() :: nhttp_qpack_encoder:state().

encoder_config()

-type encoder_config() :: nhttp_qpack_encoder:config().

field_line()

-type field_line() :: {binary(), binary()}.

Functions

decode_field_section(Decoder, StreamId, Data)

-spec decode_field_section(decoder(), nhttp_lib:stream_id(), binary()) ->
                              {ok, decoder(), iodata(), [field_line()]} |
                              {blocked, decoder()} |
                              {error, term()}.

Decode an encoded field section from a request or push stream. Returns {ok, Decoder, DecoderStreamData, FieldLines} on success, {blocked, Decoder} when the field section references entries not yet received on the encoder stream, or {error, Reason} on failure.

encode_field_section(Encoder, StreamId, Headers)

-spec encode_field_section(encoder(), nhttp_lib:stream_id(), [field_line()]) ->
                              {ok, encoder(), iodata(), iodata()}.

Encode a field section for the given stream.

Returns encoder stream data (to send on the encoder unidirectional stream) and field section data (to send on the request stream).

feed_decoder_stream(Encoder, Data)

-spec feed_decoder_stream(encoder(), binary()) -> {ok, encoder()} | {error, term()}.

Feed decoder stream data into the encoder. Processes section acknowledgments, stream cancellations, and insert count increments from the decoder.

feed_encoder_stream(Decoder, Data)

-spec feed_encoder_stream(decoder(), binary()) ->
                             {ok, decoder(), [{nhttp_lib:stream_id(), iodata(), [field_line()]}]} |
                             {error, term()}.

Feed encoder stream data into the decoder. Processes encoder instructions (table insertions, capacity changes, duplications) and unblocks any streams whose required insert count is now satisfied. Returns {ok, Decoder, UnblockedResults} where UnblockedResults is a list of {StreamId, DecoderStreamData, FieldLines} tuples for streams that became unblocked.

new_decoder(Config)

-spec new_decoder(decoder_config()) -> {ok, decoder()}.

Create a new QPACK decoder.

new_encoder(Config)

-spec new_encoder(encoder_config()) -> {ok, encoder()}.

Create a new QPACK encoder.

reconcile_peer_limits(PeerMaxCap, PeerMaxBlocked, Encoder)

-spec reconcile_peer_limits(non_neg_integer(), non_neg_integer(), encoder()) -> encoder().

Reconcile the encoder against the peer's advertised QPACK limits (SETTINGS_QPACK_MAX_TABLE_CAPACITY and SETTINGS_QPACK_BLOCKED_STREAMS). Call once when the peer's HTTP/3 SETTINGS are received. See nhttp_qpack_encoder:reconcile_peer_limits/3.