nhttp_qpack_decoder (nhttp_lib v1.1.1)

View Source

QPACK decoder state machine (RFC 9204 Section 2.2).

Processes encoded field sections and encoder stream instructions. Maintains the dynamic table, handles blocked streams, and emits decoder instructions (section acknowledgments, insert count increments) back to the encoder.

The decoder receives:

When a field section references a dynamic table entry that has not yet been inserted, the stream is blocked until the encoder stream delivers the missing entries.

Every field name and every field value that arrives as a literal is read against the rule of RFC 9113 §8.2.1, which RFC 9114 §4.1.2 repeats. A refusal returns field_error/0, which is outside the decompression error set, because the two carry different severity: RFC 9114 §4.1.2 makes a malformed field a stream error, and RFC 9204 §2.2 makes a decompression failure a connection error. An invalid field never enters the dynamic table, so a name or a value that arrives as a table index needs no second read.

Summary

Types

A field that arrived from the peer breaks the rule of RFC 9113 §8.2.1, which RFC 9114 §4.1.2 repeats for HTTP/3. The third element is the field name, so that a caller can name the offending field in its diagnostic.

Functions

Decode an encoded field section from a request or push stream.

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, NewState, UnblockedResults} where UnblockedResults is a list of {StreamId, DecoderStreamData, FieldLines} tuples for streams that became unblocked.

Create a new QPACK decoder with the given configuration.

Types

config()

-type config() :: #{max_table_capacity => non_neg_integer(), max_blocked_streams => non_neg_integer()}.

field_error()

-type field_error() :: {invalid_field, field_reason(), binary()}.

A field that arrived from the peer breaks the rule of RFC 9113 §8.2.1, which RFC 9114 §4.1.2 repeats for HTTP/3. The third element is the field name, so that a caller can name the offending field in its diagnostic.

This shape is deliberately outside the decompression error set. RFC 9114 §4.1.2 makes a malformed field a stream error of type H3_MESSAGE_ERROR, where a decompression failure is a connection error of type QPACK_DECOMPRESSION_FAILED (RFC 9204 §2.2).

field_line()

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

field_reason()

state()

-opaque state()

unblocked_result()

-type unblocked_result() :: {nhttp_lib:stream_id(), iodata(), [field_line()]}.

Functions

decode_field_section(State, StreamId, Data)

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

Decode an encoded field section from a request or push stream.

Returns {ok, NewState, DecoderStreamData, FieldLines} on success, {blocked, NewState} when the required insert count exceeds the current insert count, or {error, Reason} on failure.

feed_encoder_stream(State, Data)

-spec feed_encoder_stream(state(), binary()) -> {ok, state(), [unblocked_result()]} | {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, NewState, UnblockedResults} where UnblockedResults is a list of {StreamId, DecoderStreamData, FieldLines} tuples for streams that became unblocked.

new(Config)

-spec new(config()) -> {ok, state()}.

Create a new QPACK decoder with the given configuration.