HPAX (HPAX v0.1.0) View Source
Support for the HPACK header compression algorithm.
This module provides support for the HPACK header compression algorithm used mainly in HTTP/2.
Encoding and decoding contexts
The HPACK algorithm requires both
- an encoding context on the encoder side
- a decoding context on the decoder side
These contexts are semantically different but structurally the same. In HPACK they are implemented as HPACK tables. This library uses the name "tables" everywhere internally
HPACK tables can be created through the new/1
function.
Link to this section Summary
Functions
Decodes a header block fragment (HBF) through a given table.
Encodes a list of headers through the given table.
Create a new HPACK table that can be used as encoding or decoding context.
Resizes the given table to the given size.
Link to this section Types
Link to this section Functions
Specs
decode(binary(), HPAX.Table.t()) :: {:ok, [{header_name(), header_value()}], HPAX.Table.t()} | {:error, term()}
Decodes a header block fragment (HBF) through a given table.
If decoding is successful, this function returns a {:ok, headers, updated_table}
tuple where
headers
is a list of decoded headers, and updated_table
is the updated table. If there's
an error in decoding, this function returns {:error, reason}
.
Examples
decoding_context = HPAX.new(1000)
hbf = get_hbf_from_somewhere()
HPAX.decode(hbf, decoding_context)
#=> {:ok, [{":method", "GET"}], decoding_context}
Specs
encode([header], HPAX.Table.t()) :: {iodata(), HPAX.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 table.
Returns a two-element tuple where the first element is a binary representing the encoded headers and the second element is an updated table.
Examples
headers = [{:store, ":authority", "https://example.com"}]
encoding_context = HPAX.new(1000)
HPAX.encode(headers, encoding_context)
#=> {iodata, updated_encoding_context}
Specs
new(non_neg_integer()) :: HPAX.Table.t()
Create a new HPACK table that can be used as encoding or decoding context.
See the "Encoding and decoding contexts" section in the module documentation.
max_table_size
is the maximum table size (in bytes) for the newly created table.
Examples
encoding_context = HPAX.new(4096)
Specs
resize(HPAX.Table.t(), non_neg_integer()) :: HPAX.Table.t()
Resizes the given table to the given size.
Examples
decoding_context = HPAX.new(4096)
HPAX.resize(decoding_context, 8192)