livery_h2 (livery v0.1.0)
View SourceHTTP/2 adapter on top of the h2 library.
Starts an h2 server bound to a Livery middleware stack and
handler. For every inbound request the adapter:
- Builds a
#livery_req{}from the method, path, and headers delivered byh2. - Spawns a
livery_req_procworker underlivery_req_sup. - Spawns a small translator process that turns
{h2, Conn, _}body and trailer events into the{livery_body, Ref, _}shape the worker reads vialivery_body. - Registers the translator as the
h2stream handler.
Response emission goes through livery:emit/3 and lands on the
adapter callbacks (send_headers/4, send_data/3,
send_trailers/2, reset/2), which call into
h2:send_response/4, h2:send_data/3,4, and
h2:send_trailers/3. extended_connect is reported as supported
in capabilities/1.
Summary
Functions
Accept a WebSocket session on an extended-CONNECT stream.
Hand an extended-CONNECT stream to the webtransport library.
Start a listener with the given options.
Types
-type listen_opts() :: #{port => inet:port_number(), transport => tcp | ssl, cert => binary() | string(), key => binary() | string(), cacerts => [binary()], acceptors => pos_integer(), enable_connect_protocol => boolean(), max_body => non_neg_integer() | infinity, stack := livery_middleware:stack(), handler := livery_middleware:handler()}.
-type listener() :: h2:server_ref().
-type stream() :: {h2:connection(), h2:stream_id()}.
Functions
Accept a WebSocket session on an extended-CONNECT stream.
Validates the RFC 8441 handshake, replies 200 (extended CONNECT
uses 200, not 101), then hands the stream to the ws library
driven by the livery_ws_h2 transport.
-spec accept_wt(h2, livery_req:req(), module(), term()) -> {ok, pid()} | {error, term()}.
Hand an extended-CONNECT stream to the webtransport library.
Reconstructs the CONNECT pseudo-headers from the request value
(the adapter delivers method/path out of band, but
webtransport:accept/4 expects them inline) and calls
webtransport:accept/4 with transport => h2.
-spec capabilities(listener()) -> livery_adapter:capabilities().
-spec peer_info(stream()) -> livery_adapter:peer_info().
-spec send_data(stream(), iodata(), livery_adapter:send_opts()) -> livery_adapter:send_result().
-spec send_headers(stream(), 100..599, [{binary(), binary()}], livery_adapter:send_opts()) -> livery_adapter:send_result().
-spec send_trailers(stream(), [{binary(), binary()}]) -> livery_adapter:send_result().
-spec start(listen_opts()) -> {ok, listener()} | {error, term()}.
Start a listener with the given options.
Opts must include stack and handler. port defaults to 0
(random port). transport defaults to tcp for h2c; pass ssl
plus cert and key to serve over TLS with ALPN-negotiated h2.
-spec start(atom() | undefined, listen_opts(), map()) -> {ok, listener()} | {error, term()}.
-spec stop(listener()) -> ok.