nhttp_qpack_decoder (nhttp_lib v1.1.1)
View SourceQPACK 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:
- Encoded field sections on request/push streams via
decode_field_section/3 - Encoder stream data via
feed_encoder_stream/2
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
-type config() :: #{max_table_capacity => non_neg_integer(), max_blocked_streams => non_neg_integer()}.
-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).
-type field_reason() :: nhttp_headers:field_name_error() | nhttp_headers:field_value_error().
-opaque state()
-type unblocked_result() :: {nhttp_lib:stream_id(), iodata(), [field_line()]}.
Functions
-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.
-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.
Create a new QPACK decoder with the given configuration.