jhn_hpack (jhn_stdlib v5.10.1)

View Source

A HPACK library based on:

HPACK: Header Compression for HTTP/2 (rfc7541)

The headers are represented as a list of header, value binary tuples and and the dynamic index size update by the tuple {size_update, Integer}. The context is configurable with a max size and a hard limit in the size.

For the encoding context a without and never list of header names can be provided. The decoding context contains a list of the never index that can be selected from the context.

Summary

Functions

Decodes the binary into a list of headers and a context. Equivalent of decode(HPACK, #{}).

Decodes the binary into headers and a context used in futher decodings. First call is made with options, following calls with the context returned from the previous call to decode/2. Decode will give an exception if the binary is not well formed. Options are: limit => integer() -> the limit for the max size value, default 4096 max => integer() -> the max size for the dynamic table default 4096

Encodes the structured Erlang term as a binary and a context. Equivalent of encode(Fields, #{}).

Encodes the list of HPACK fields as an iolist or binary and a context used in futher encodings. First call is made with options, following calls with the context returned from the previous call to encode/2. Encode will give an exception if the erlang term is not well formed. Options are: return_type => binary | iolist -> default binary limit => integer() -> the limit for the max size value, default 4096 max => integer() -> the max size for the dynamic table default 4096 huffman_encode => boolean() -> if strings should be huffman encoded, default false without() => [header_name()] -> headers not to be indexed, default [] never() => [header_name()] -> headers never indexed, default []

Selects the header names that are marked as never in the decoding context.

Types

context/0

-type context() ::
          #context{table :: [header()],
                   without :: [header_name()],
                   never :: [header_name()],
                   max :: non_neg_integer(),
                   limit :: non_neg_integer(),
                   length :: non_neg_integer(),
                   size :: non_neg_integer(),
                   huffman_encode :: boolean(),
                   return_type :: binary | iolist}.

field/0

-type field() :: header() | size_update().

header/0

-type header() :: {header_name(), header_value()}.

header_name/0

-type header_name() :: binary().

header_value/0

-type header_value() :: binary().

opts/0

-type opts() ::
          #{limit => non_neg_integer(), return_type => binary | iolist, huffman_encode => boolean()}.

size_update/0

-type size_update() :: {size_update, non_neg_integer()}.

Functions

decode(Bin)

-spec decode(binary()) -> {ok, [header()], context()}.

Decodes the binary into a list of headers and a context. Equivalent of decode(HPACK, #{}).

decode(Bin, Ctx)

-spec decode(binary(), context() | opts()) -> {ok, [header()], context()}.

Decodes the binary into headers and a context used in futher decodings. First call is made with options, following calls with the context returned from the previous call to decode/2. Decode will give an exception if the binary is not well formed. Options are: limit => integer() -> the limit for the max size value, default 4096 max => integer() -> the max size for the dynamic table default 4096

encode(Headers)

-spec encode([field()]) -> {ok, binary(), context()}.

Encodes the structured Erlang term as a binary and a context. Equivalent of encode(Fields, #{}).

encode(Headers, Ctx)

-spec encode([field()], context() | opts()) -> {ok, iodata(), context()}.

Encodes the list of HPACK fields as an iolist or binary and a context used in futher encodings. First call is made with options, following calls with the context returned from the previous call to encode/2. Encode will give an exception if the erlang term is not well formed. Options are: return_type => binary | iolist -> default binary limit => integer() -> the limit for the max size value, default 4096 max => integer() -> the max size for the dynamic table default 4096 huffman_encode => boolean() -> if strings should be huffman encoded, default false without() => [header_name()] -> headers not to be indexed, default [] never() => [header_name()] -> headers never indexed, default []

never(Context)

-spec never(context()) -> [header_name()].

Selects the header names that are marked as never in the decoding context.