wt_h2_capsule (webtransport v0.2.3)

View Source

HTTP/2 WebTransport Capsules (draft-ietf-webtrans-http2-14)

All WebTransport data over HTTP/2 flows through capsules in the CONNECT stream body. This module handles encoding and decoding of WebTransport-specific capsule types.

Summary

Functions

Construct a CLOSE_SESSION capsule with the given error code and no reason.

Construct a CLOSE_SESSION capsule with the given error code and reason. draft-14 §4.6: the Reason field MUST be at most 1024 UTF-8 bytes.

Construct a DATA_BLOCKED capsule indicating the connection-level limit reached.

Construct a DATAGRAM capsule wrapping the given payload.

Decode the first capsule from a binary, returning the capsule and remaining bytes.

Decode all capsules from binary.

Construct a DRAIN_SESSION capsule to signal graceful shutdown.

Encode a capsule record into its wire-format binary.

Construct a MAX_DATA capsule with the given connection-level limit.

Construct a MAX_STREAM_DATA capsule for the given stream and limit.

Construct a MAX_STREAMS capsule for bidirectional streams.

Construct a MAX_STREAMS capsule for unidirectional streams.

Construct a PADDING capsule of the given size or from raw bytes.

Construct a RESET_STREAM capsule for the given stream and error code.

Construct a STOP_SENDING capsule for the given stream and error code.

Construct a STREAM_DATA_BLOCKED capsule for the given stream and limit.

Construct a STREAMS_BLOCKED capsule for bidirectional streams.

Construct a STREAMS_BLOCKED capsule for unidirectional streams.

Get the human-readable name of a capsule type.

Construct a WT_STREAM capsule carrying data for the given stream.

Construct a WT_STREAM or WT_STREAM_FIN capsule depending on the fin flag.

Construct a WT_STREAM_FIN capsule carrying data with the fin bit set.

Construct a WT_STREAM_FIN or WT_STREAM capsule depending on the fin flag.

Types

capsule/0

-type capsule() ::
          {padding, binary()} |
          {wt_stream, stream_id(), binary()} |
          {wt_stream_fin, stream_id(), binary()} |
          {reset_stream, stream_id(), error_code()} |
          {stop_sending, stream_id(), error_code()} |
          {max_data, non_neg_integer()} |
          {max_stream_data, stream_id(), non_neg_integer()} |
          {max_streams_bidi, non_neg_integer()} |
          {max_streams_uni, non_neg_integer()} |
          {data_blocked, non_neg_integer()} |
          {stream_data_blocked, stream_id(), non_neg_integer()} |
          {streams_blocked_bidi, non_neg_integer()} |
          {streams_blocked_uni, non_neg_integer()} |
          {close_session, error_code(), binary()} |
          {drain_session} |
          {datagram, binary()} |
          {unknown, non_neg_integer(), binary()}.

error_code/0

-type error_code() :: non_neg_integer().

stream_id/0

-type stream_id() :: non_neg_integer().

Functions

close_session(ErrorCode)

-spec close_session(error_code()) -> capsule().

Construct a CLOSE_SESSION capsule with the given error code and no reason.

close_session(ErrorCode, Reason)

-spec close_session(error_code(), binary()) -> capsule() | {error, reason_too_long}.

Construct a CLOSE_SESSION capsule with the given error code and reason. draft-14 §4.6: the Reason field MUST be at most 1024 UTF-8 bytes.

data_blocked(Limit)

-spec data_blocked(non_neg_integer()) -> capsule().

Construct a DATA_BLOCKED capsule indicating the connection-level limit reached.

datagram(Data)

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

Construct a DATAGRAM capsule wrapping the given payload.

decode(Bin)

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

Decode the first capsule from a binary, returning the capsule and remaining bytes.

decode_all(Bin)

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

Decode all capsules from binary.

drain_session()

-spec drain_session() -> capsule().

Construct a DRAIN_SESSION capsule to signal graceful shutdown.

encode(_)

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

Encode a capsule record into its wire-format binary.

max_data(Limit)

-spec max_data(non_neg_integer()) -> capsule().

Construct a MAX_DATA capsule with the given connection-level limit.

max_stream_data(StreamId, Limit)

-spec max_stream_data(stream_id(), non_neg_integer()) -> capsule().

Construct a MAX_STREAM_DATA capsule for the given stream and limit.

max_streams_bidi(Limit)

-spec max_streams_bidi(non_neg_integer()) -> capsule().

Construct a MAX_STREAMS capsule for bidirectional streams.

max_streams_uni(Limit)

-spec max_streams_uni(non_neg_integer()) -> capsule().

Construct a MAX_STREAMS capsule for unidirectional streams.

padding(Size)

-spec padding(non_neg_integer() | binary()) -> capsule().

Construct a PADDING capsule of the given size or from raw bytes.

reset_stream(StreamId, ErrorCode)

-spec reset_stream(stream_id(), error_code()) -> capsule().

Construct a RESET_STREAM capsule for the given stream and error code.

stop_sending(StreamId, ErrorCode)

-spec stop_sending(stream_id(), error_code()) -> capsule().

Construct a STOP_SENDING capsule for the given stream and error code.

stream_data_blocked(StreamId, Limit)

-spec stream_data_blocked(stream_id(), non_neg_integer()) -> capsule().

Construct a STREAM_DATA_BLOCKED capsule for the given stream and limit.

streams_blocked_bidi(Limit)

-spec streams_blocked_bidi(non_neg_integer()) -> capsule().

Construct a STREAMS_BLOCKED capsule for bidirectional streams.

streams_blocked_uni(Limit)

-spec streams_blocked_uni(non_neg_integer()) -> capsule().

Construct a STREAMS_BLOCKED capsule for unidirectional streams.

type_name(N)

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

Get the human-readable name of a capsule type.

wt_stream(StreamId, Data)

-spec wt_stream(stream_id(), binary()) -> capsule().

Construct a WT_STREAM capsule carrying data for the given stream.

wt_stream(StreamId, Data, _)

-spec wt_stream(stream_id(), binary(), boolean()) -> capsule().

Construct a WT_STREAM or WT_STREAM_FIN capsule depending on the fin flag.

wt_stream_fin(StreamId, Data)

-spec wt_stream_fin(stream_id(), binary()) -> capsule().

Construct a WT_STREAM_FIN capsule carrying data with the fin bit set.

wt_stream_fin(StreamId, Data, _)

-spec wt_stream_fin(stream_id(), binary(), boolean()) -> capsule().

Construct a WT_STREAM_FIN or WT_STREAM capsule depending on the fin flag.