xclient v0.6.0-vendored-xhttp XHTTP2.HPACK View Source

Support for the HPACK header compression algorithm.

This module provides support for the HPACK header compression algorithm used mainly in HTTP/2. The HPACK algorithm requires an encoding context on the encoder side and a decoding context on the decoder side. These contexts are semantically different but structurally the same and they can both be created through new/1.

Link to this section Summary

Functions

Decodes a header block fragment (HBF) through a given context

Encodes a list of headers through the given context

Create a new context

Resizes the given table to the given size

Link to this section Types

Link to this type header_name() View Source
header_name() :: binary()
Link to this type header_value() View Source
header_value() :: binary()

Link to this section Functions

Link to this function decode(block, table) View Source
decode(binary(), XHTTP2.HPACK.Table.t()) ::
  {:ok, [{binary(), binary()}], XHTTP2.HPACK.Table.t()} | {:error, term()}

Decodes a header block fragment (HBF) through a given context.

If decoding is successful, this function returns a {:ok, headers, updated_context} tuple where headers is a list of decoded headers, and updated_context is the updated context. If there’s an error in decoding, this function returns {:error, reason}.

Examples

context = HPACK.new(1000)
hbf = get_hbf_from_somewhere()
HPACK.decode(hbf, context)
#=> {:ok, [{":method", "GET"}], updated_context}
Link to this function encode(headers, table) View Source
encode([header], XHTTP2.HPACK.Table.t()) :: {iodata(), XHTTP2.HPACK.Table.t()}
when header: {action, header_name(), header_value()},
     action: :store | :store_name | :no_store | :never_store

Encodes a list of headers through the given context.

Returns a two-element tuple where the first element is a binary representing the encoded headers and the second element is an updated context.

Examples

headers = [{":authority", "https://example.com"}]
context = HPACK.new(1000)
HPACK.encode(headers, context)
#=> {<<...>>, updated_context}
Link to this function new(max_table_size) View Source
new(non_neg_integer()) :: XHTTP2.HPACK.Table.t()

Create a new context.

max_table_size is the maximum table size (in bytes) for the newly created context.

Link to this function resize(table, new_size) View Source
resize(XHTTP2.HPACK.Table.t(), non_neg_integer()) :: XHTTP2.HPACK.Table.t()

Resizes the given table to the given size.