hpack v3.0.1 HPack

Implementation of the HPack protocol, a compression format for efficiently representing HTTP header fields, to be used in HTTP/2.

Link to this section Summary

Functions

Decodes a header block fragment as specified in RFC 7541.

Encodes a list of headers into a header block fragment as specified in RFC 7541.

Link to this section Types

Link to this type

header()

header() :: {name(), value()}
Link to this type

header_block_fragment()

header_block_fragment() :: binary()
Link to this type

headers()

headers() :: [header()]
Link to this type

name()

name() :: String.t()
Link to this type

value()

value() :: String.t()

Link to this section Functions

Link to this function

decode(hbf, table, max_size \\ nil)

decode(header_block_fragment(), HPack.Table.t(), HPack.Table.size() | nil) ::
  {:ok, HPack.Table.t(), headers()} | {:error, :decode_error}

Decodes a header block fragment as specified in RFC 7541.

Returns the decoded headers as a List.

Examples

iex> ctx = HPack.Table.new(1000)
iex> HPack.decode(<< 0x82 >>, ctx)
{:ok, %HPack.Table{size: 1000, table: []}, [{":method", "GET"}]}
Link to this function

encode(headers, table)

encode(headers(), HPack.Table.t()) ::
  {:ok, HPack.Table.t(), header_block_fragment()} | {:error, :encode_error}

Encodes a list of headers into a header block fragment as specified in RFC 7541.

Returns the header block fragment.

Examples

iex> ctx = HPack.Table.new(1000)
iex> HPack.encode([{":method", "GET"}], ctx)
{:ok, %HPack.Table{size: 1000, table: []}, << 0b10000010 >>}