h2_capsule (h2 v0.6.0)

View Source

RFC 9297 Capsule Protocol

Capsules are used to convey control information in HTTP CONNECT tunnels. Used by HTTP/2 WebTransport for stream multiplexing within a CONNECT stream.

Capsule format: +------------+------------+ | Type (i) | Length (i) | +------------+------------+ | Payload (*) | +-------------------------+

Type and Length are QUIC variable-length integers.

Summary

Functions

Create a DATAGRAM capsule.

Decode a single capsule from binary. Returns {ok, {Type, Payload}, Rest} | {more, N} | {error, Reason}

Decode all capsules from binary.

Convert capsule type integer to atom (if known).

Encode a capsule to binary.

Convert capsule type atom to integer.

Types

capsule/0

-type capsule() :: {Type :: capsule_type(), Payload :: binary()}.

capsule_type/0

-type capsule_type() :: non_neg_integer() | atom().

Functions

datagram(Payload)

-spec datagram(binary()) -> capsule().

Create a DATAGRAM capsule.

decode(Bin)

-spec decode(binary()) -> {ok, capsule(), binary()} | {more, pos_integer()} | {error, term()}.

Decode a single capsule from binary. Returns {ok, {Type, Payload}, Rest} | {more, N} | {error, Reason}

decode_all(Bin)

-spec decode_all(binary()) -> {ok, [capsule()], binary()}.

Decode all capsules from binary.

decode_type(N)

-spec decode_type(non_neg_integer()) -> non_neg_integer() | atom().

Convert capsule type integer to atom (if known).

encode(Type, Payload)

-spec encode(capsule_type(), binary()) -> binary().

Encode a capsule to binary.

encode_type(_)

-spec encode_type(atom()) -> non_neg_integer().

Convert capsule type atom to integer.