wt_h3_capsule (webtransport v0.2.6)

View Source

HTTP/3 WebTransport capsules and stream/datagram headers.

HTTP/3 WebTransport uses: - capsules on the CONNECT stream for session control and flow control - native QUIC stream headers for data streams - HTTP Datagram framing for unreliable datagrams

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-15 §5: the Reason field MUST be at most 1024 UTF-8 bytes.

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

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

Decode all capsules from a binary, returning the list and any trailing bytes.

Decode an HTTP Datagram, returning the session ID and payload.

Decode a WebTransport stream header, returning the session ID and stream kind.

Construct a DRAIN_SESSION capsule to signal graceful shutdown.

Encode a capsule record into its wire-format binary.

Encode a bidirectional WebTransport stream header for the given session.

Encode an HTTP Datagram payload with the quarter stream ID prefix.

Encode a unidirectional WebTransport stream header for the given session.

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

Construct a MAX_STREAMS capsule for bidirectional streams.

Construct a MAX_STREAMS capsule for unidirectional streams.

Convert a session ID to its quarter stream ID for datagram framing.

Convert a quarter stream ID back to the original session ID.

Construct a STREAMS_BLOCKED capsule for bidirectional streams.

Construct a STREAMS_BLOCKED capsule for unidirectional streams.

Return the human-readable atom for a capsule type code.

Types

capsule/0

-type capsule() ::
          {max_data, non_neg_integer()} |
          {data_blocked, non_neg_integer()} |
          {max_streams_bidi, non_neg_integer()} |
          {max_streams_uni, non_neg_integer()} |
          {streams_blocked_bidi, non_neg_integer()} |
          {streams_blocked_uni, non_neg_integer()} |
          {close_session, non_neg_integer(), binary()} |
          {drain_session} |
          {unknown, non_neg_integer(), binary()}.

stream_kind/0

-type stream_kind() :: bidi | uni.

Functions

close_session(ErrorCode)

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

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

close_session(ErrorCode, Reason)

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

Construct a CLOSE_SESSION capsule with the given error code and reason. draft-15 §5: 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.

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 a binary, returning the list and any trailing bytes.

decode_datagram(Bin)

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

Decode an HTTP Datagram, returning the session ID and payload.

decode_stream_header(Bin)

-spec decode_stream_header(binary()) ->
                              {ok, non_neg_integer(), stream_kind(), binary()} |
                              {more, pos_integer()} |
                              {error, term()}.

Decode a WebTransport stream header, returning the session ID and stream kind.

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.

encode_bidi_stream_header(SessionId)

-spec encode_bidi_stream_header(non_neg_integer()) -> binary().

Encode a bidirectional WebTransport stream header for the given session.

encode_datagram(SessionId, Data)

-spec encode_datagram(non_neg_integer(), binary()) -> binary().

Encode an HTTP Datagram payload with the quarter stream ID prefix.

encode_uni_stream_header(SessionId)

-spec encode_uni_stream_header(non_neg_integer()) -> binary().

Encode a unidirectional WebTransport stream header for the given session.

max_data(Limit)

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

Construct a MAX_DATA capsule with the given connection-level 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.

quarter_stream_id(SessionId)

-spec quarter_stream_id(non_neg_integer()) -> non_neg_integer().

Convert a session ID to its quarter stream ID for datagram framing.

session_id_from_quarter_stream_id(QuarterStreamId)

-spec session_id_from_quarter_stream_id(non_neg_integer()) -> non_neg_integer().

Convert a quarter stream ID back to the original session ID.

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().

Return the human-readable atom for a capsule type code.