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 section Functions
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}
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}
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.
resize(XHTTP2.HPACK.Table.t(), non_neg_integer()) :: XHTTP2.HPACK.Table.t()
Resizes the given table to the given size.