nhttp_hpack (nhttp_lib v1.0.0)
View SourceHPACK header compression for HTTP/2 (RFC 7541).
This module implements the HPACK header compression format used by HTTP/2. It provides stateful encoding and decoding of header fields using static and dynamic tables.
Usage
{ok, EncState0} = nhttp_hpack:new(),
{ok, DecState0} = nhttp_hpack:new(),
Headers = [{<<":method">>, <<"GET">>}, {<<":path">>, <<"/">>}],
{ok, HeaderBlock, EncState1} = nhttp_hpack:encode(Headers, EncState0),
{ok, DecodedHeaders, DecState1} = nhttp_hpack:decode(HeaderBlock, DecState0).
Summary
Functions
Decode a header block.
Decode a header block, aborting with {error, header_list_too_large} once
the cumulative decoded list size exceeds max_list_size. The check matches
the RFC 9113 §10.5.1 octet count (name + value + 32 per entry).
Encode headers without Huffman encoding.
Encode headers with options.
Check if the dynamic table is empty.
Create a new HPACK state with default max size (4096 bytes).
Create a new HPACK state with specified max size.
Update the maximum table size (from SETTINGS_HEADER_TABLE_SIZE). Immediately evicts entries if the new size is smaller than current table size.
Get the current dynamic table size in bytes.
Types
-type decode_error() ::
dynamic_table_size_exceeded | invalid_table_index | integer_overflow | invalid_huffman |
incomplete_header_block | header_list_too_large | uppercase_header_name.
-type decode_opts() :: #{max_list_size => pos_integer() | infinity}.
-type encode_opts() :: #{huffman => boolean()}.
-opaque state()
Functions
-spec decode(Data :: binary(), State :: state()) -> {ok, Headers :: headers(), NewState :: state()} | {error, decode_error()}.
Decode a header block.
-spec decode(Data :: binary(), State :: state(), Opts :: decode_opts()) -> {ok, Headers :: headers(), NewState :: state()} | {error, decode_error()}.
Decode a header block, aborting with {error, header_list_too_large} once
the cumulative decoded list size exceeds max_list_size. The check matches
the RFC 9113 §10.5.1 octet count (name + value + 32 per entry).
Encode headers without Huffman encoding.
-spec encode(Headers :: headers(), State :: state(), Opts :: encode_opts()) -> {ok, iodata(), state()}.
Encode headers with options.
Check if the dynamic table is empty.
-spec new() -> {ok, state()}.
Create a new HPACK state with default max size (4096 bytes).
-spec new(MaxSize :: non_neg_integer()) -> {ok, state()}.
Create a new HPACK state with specified max size.
-spec set_max_table_size(MaxSize :: non_neg_integer(), State :: state()) -> {ok, state()}.
Update the maximum table size (from SETTINGS_HEADER_TABLE_SIZE). Immediately evicts entries if the new size is smaller than current table size.
-spec table_size(State :: state()) -> non_neg_integer().
Get the current dynamic table size in bytes.