livery_h1 (livery v0.1.0)
View SourceHTTP/1.1 adapter on top of the h1 library.
Starts an h1 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 byh1. - Spawns a
livery_req_procworker underlivery_req_sup. - Spawns a small translator that turns
{h1, Conn, _}body and trailer events into the{livery_body, Ref, _}shape the worker reads vialivery_body. - Registers the translator as the
h1stream handler so the engine never blocks on the worker.
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 in turn call into
h1:send_response/4, h1:send_data/3,4, and
h1:send_trailers/3.
Summary
Functions
Hand the stream's socket to the ws library to run a WebSocket
session.
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(), max_body => non_neg_integer() | infinity, idle_timeout => timeout(), request_timeout => timeout(), handshake_timeout => timeout(), max_keepalive_requests => pos_integer() | infinity, stack := livery_middleware:stack(), handler := livery_middleware:handler()}.
-type listener() :: h1:server_ref().
-type stream() :: {h1:connection(), h1:stream_id()}.
Functions
Hand the stream's socket to the ws library to run a WebSocket
session.
Validates the RFC 6455 handshake headers, replies 101 via
h1:accept_upgrade/3, takes ownership of the raw socket, and
calls ws:accept/5 with the supplied handler module and opts.
Returns {ok, SessionPid} on success or {error, _} on a bad
handshake or socket transfer failure.
-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. Returns the same
listener handle the h1 library does, suitable for passing to
stop/1 or to h1:server_port/1.
-spec start(atom() | undefined, listen_opts(), map()) -> {ok, listener()} | {error, term()}.
-spec stop(listener()) -> ok.