webtransport_h2 (webtransport v0.2.5)
View SourceHTTP/2 WebTransport runtime wrapper.
WebTransport over HTTP/2 uses a single CONNECT stream to multiplex all WebTransport data through capsules. This module manages the CONNECT stream and handles capsule encoding/decoding.
Key differences from HTTP/3 transport:
- All streams are multiplexed over one HTTP/2 stream using capsules
- Flow control is managed via capsules, not native QUIC flow control
- Datagrams use the DATAGRAM capsule type
See also: wt_h2_capsule.
Summary
Functions
Send a CLOSE_WEBTRANSPORT_SESSION capsule and FIN the CONNECT stream.
Establish an HTTP/2 WebTransport session to the given host, port, and path.
Return the HTTP/2 CONNECT stream ID used for this session.
Decode a single capsule from the binary buffer, returning any remainder.
Decode all complete capsules from the binary buffer, returning the unparsed tail.
Send a DRAIN_WEBTRANSPORT_SESSION capsule to signal graceful shutdown.
Return the HTTP/2 connection pid.
Return true if the response headers contain a 2xx status code.
Create a new H2 transport state for the given CONNECT stream.
No-op: H2 streams are implicitly opened when first used via capsules.
Return the peer's advertised WebTransport settings.
Build CONNECT request headers for an H2 WebTransport session.
Build CONNECT request headers with additional custom headers.
Reset a multiplexed stream by sending a WT_RESET_STREAM capsule.
Send data on a multiplexed stream via a WT_STREAM capsule.
Write a pre-built capsule on the CONNECT stream (e.g. for flow-control signalling).
Send an unreliable datagram via the DATAGRAM capsule type.
Request the peer stop sending on a stream via a WT_STOP_SENDING capsule.
Return a new state with updated peer settings.
Types
Functions
-spec close_session(state(), non_neg_integer(), binary()) -> ok | {error, term()}.
Send a CLOSE_WEBTRANSPORT_SESSION capsule and FIN the CONNECT stream.
-spec connect(string() | binary(), inet:port_number(), binary(), map()) -> {ok, state()} | {error, term()}.
Establish an HTTP/2 WebTransport session to the given host, port, and path.
-spec connect_stream_id(state()) -> non_neg_integer().
Return the HTTP/2 CONNECT stream ID used for this session.
-spec decode_capsule(binary()) -> {ok, wt_h2_capsule:capsule(), binary()} | {more, pos_integer()} | {error, term()}.
Decode a single capsule from the binary buffer, returning any remainder.
-spec decode_capsules(binary()) -> {ok, [wt_h2_capsule:capsule()], binary()} | {error, term()}.
Decode all complete capsules from the binary buffer, returning the unparsed tail.
Send a DRAIN_WEBTRANSPORT_SESSION capsule to signal graceful shutdown.
Return the HTTP/2 connection pid.
Return true if the response headers contain a 2xx status code.
-spec new(pid(), non_neg_integer()) -> state().
Create a new H2 transport state for the given CONNECT stream.
-spec open_stream(state(), non_neg_integer(), bidi | uni) -> ok | {error, term()}.
No-op: H2 streams are implicitly opened when first used via capsules.
Return the peer's advertised WebTransport settings.
Build CONNECT request headers for an H2 WebTransport session.
Build CONNECT request headers with additional custom headers.
-spec reset_stream(state(), non_neg_integer(), non_neg_integer()) -> ok | {error, term()}.
Reset a multiplexed stream by sending a WT_RESET_STREAM capsule.
-spec send(state(), non_neg_integer(), iodata(), boolean()) -> ok | {error, term()}.
Send data on a multiplexed stream via a WT_STREAM capsule.
-spec send_capsule(state(), wt_h2_capsule:capsule()) -> ok | {error, term()}.
Write a pre-built capsule on the CONNECT stream (e.g. for flow-control signalling).
Send an unreliable datagram via the DATAGRAM capsule type.
-spec stop_sending(state(), non_neg_integer(), non_neg_integer()) -> ok | {error, term()}.
Request the peer stop sending on a stream via a WT_STOP_SENDING capsule.
Return a new state with updated peer settings.