livery_wt (livery v0.13.0)

View Source

WebTransport integration on top of the webtransport library.

A handler that wants to accept a WebTransport session (initiated by an HTTP extended CONNECT with :protocol = webtransport) calls upgrade/3. The function dispatches to the adapter's accept_wt/4 helper, which reconstructs the CONNECT pseudo-headers and calls webtransport:accept/4. On success the stream/session belongs to the webtransport session process and upgrade/3 returns the taken_over sentinel response.

my_wt_route(Req) ->
    livery_wt:upgrade(Req, my_wt_handler, #{}).

my_wt_handler implements the webtransport_handler behaviour (from erlang-webtransport).

WebTransport runs only over H2 (extended CONNECT, RFC 8441) and H3 (RFC 9220). Calling upgrade/3 on an adapter that does not implement accept_wt/4 (H1) returns 501 Not Implemented.

The listener must advertise the WebTransport settings. Merge webtransport:h3_settings/0 (or h2_settings/0) into the listener options so the adapter forwards the H3/H2 SETTINGS, datagram support, and WT stream routing to the wire library:

Opts = maps:merge(webtransport:h3_settings(), #{
    cert => Cert, key => Key, stack => Stack,
    handler => fun(Req) -> livery_wt:upgrade(Req, my_handler, #{}) end
}),
livery_h3:start(Opts).

Over H2 a session needs TLS 1.3 (webtransport >= 0.5).

End-to-end bidi-stream and datagram echo over a real session is covered by livery_wt_SUITE.

Summary

Functions

Accept a WebTransport session on the current request.

Types

handler_module()

-type handler_module() :: module().

handler_opts()

-type handler_opts() :: term().

Functions

upgrade(Req, HandlerMod, Opts)

Accept a WebTransport session on the current request.

HandlerMod implements webtransport_handler. Returns the taken_over sentinel on success, 501 on H1, or 4xx/5xx text when the handshake is rejected.