h2_hpack (h2 v0.6.0)

View Source

HPACK Header Compression for HTTP/2 (RFC 7541)

This module provides HPACK encoding and decoding for HTTP/2 headers.

HPACK uses: - Static table: 61 predefined header name/value pairs - Dynamic table: Runtime-populated entries (FIFO eviction) - Huffman coding: Optional string compression - Integer encoding: Variable-length prefix encoding

Summary

Functions

Decode a HPACK-encoded header block.

Decode an integer with given prefix size.

Encode a list of headers.

Encode an integer with given prefix size.

Get the maximum dynamic table size.

Huffman decode a binary string.

Huffman encode a binary string.

Mark the decoder so that the next header block MUST start with a dynamic-table size update (RFC 7541 §4.2). Call this when the peer lowers SETTINGS_HEADER_TABLE_SIZE.

Create a new HPACK context with default settings.

Create a new HPACK context with specified max table size.

Set the maximum dynamic table size.

Record the peer-advertised SETTINGS_HEADER_TABLE_SIZE so the decoder can reject incoming size updates larger than this value (RFC 7541 §4.3). Also marks pending_size_update if reduced.

Types

context/0

-type context() ::
          #hpack_context{max_table_size :: non_neg_integer(),
                         table_size :: non_neg_integer(),
                         dynamic_table :: [{binary(), binary()}],
                         dynamic_table_length :: non_neg_integer(),
                         pending_size_update :: boolean(),
                         peer_max_table_size :: non_neg_integer()}.

header/0

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

headers/0

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

Functions

decode(Bin, Ctx)

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

Decode a HPACK-encoded header block.

decode_integer(Bin, Prefix)

-spec decode_integer(binary(), 1..8) -> {ok, non_neg_integer(), binary()} | {error, term()}.

Decode an integer with given prefix size.

encode(Headers, Ctx)

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

Encode a list of headers.

encode_integer(Value, Prefix)

-spec encode_integer(non_neg_integer(), 1..8) -> binary().

Encode an integer with given prefix size.

get_max_table_size(Hpack_context)

-spec get_max_table_size(context()) -> non_neg_integer().

Get the maximum dynamic table size.

huffman_decode(Bin)

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

Huffman decode a binary string.

huffman_encode(Bin)

-spec huffman_encode(binary()) -> binary().

Huffman encode a binary string.

mark_pending_size_update(Ctx)

-spec mark_pending_size_update(context()) -> context().

Mark the decoder so that the next header block MUST start with a dynamic-table size update (RFC 7541 §4.2). Call this when the peer lowers SETTINGS_HEADER_TABLE_SIZE.

new_context()

-spec new_context() -> context().

Create a new HPACK context with default settings.

new_context(MaxTableSize)

-spec new_context(non_neg_integer()) -> context().

Create a new HPACK context with specified max table size.

set_max_table_size(Size, Ctx)

-spec set_max_table_size(non_neg_integer(), context()) -> context().

Set the maximum dynamic table size.

set_peer_max_table_size(Max, Hpack_context)

-spec set_peer_max_table_size(non_neg_integer(), context()) -> context().

Record the peer-advertised SETTINGS_HEADER_TABLE_SIZE so the decoder can reject incoming size updates larger than this value (RFC 7541 §4.3). Also marks pending_size_update if reduced.