livery_adapter behaviour (livery v0.13.0)
View SourceBehaviour implemented by livery_h1, livery_h2, livery_h3, and
livery_test_adapter. An adapter written outside Livery implements it
the same way.
Adapters translate engine events into #livery_req{} values and
drive the response back onto the wire. They own no state machines;
framing, header compression, flow control, and TLS belong upstream
in h1, h2, quic, and ws.
Each adapter spawns a livery_req_proc for every incoming request
and routes body/trailers/eof messages to that pid. Once the
handler returns a #livery_resp{}, the core walks the body
variant and calls back into the adapter via the callbacks defined
here.
Callbacks
start(Name, ListenSpec, Opts) -> {ok, Listener} | {error, _}: start a listener for this adapter.stop(Listener) -> ok: stop a listener cleanly.send_headers(Stream, Status, Headers, SendOpts) -> SendResult: emit response headers.SendOptsmay carryend_stream => truewhen the response has no body.send_data(Stream, IoData, SendOpts) -> SendResult: emit body bytes.end_stream => truecloses the send half;flush => truehints the adapter to push immediately rather than batch.send_trailers(Stream, Trailers) -> SendResult: emit trailers (and implicitly close the send half).send_informational(Stream, Status, Headers) -> SendResult: optional: emit an interim (1xx) response, e.g. 103 Early Hints, ahead of the final response. May be called several times per stream. Adapters that cannot (or do not) implement it are reported asinformational => falseincapabilities/1, andlivery_req:inform/3returns{error, unsupported}.accept_ws(Stream, Req, HandlerMod, Opts) -> {ok, Pid} | {error, _}: optional: hand the stream to a WebSocket session.livery_ws:upgrade/3answers501on an adapter that does not implement it.accept_wt(Stream, Req, HandlerMod, Opts) -> {ok, Pid} | {error, _}: optional: hand the stream to a WebTransport session.livery_wt:upgrade/3answers501on an adapter that does not implement it.reset(Stream, Reason) -> ok: reset a stream with a protocol-specific reason.peer_info(Stream) -> peer_info(): return peer/TLS info for a stream.capabilities(Listener) -> capabilities(): return the capability bitmap of a listener.
Summary
Functions
Whether Adapter implements the optional callback Fun/Arity.
Types
-type listen_spec() :: term().
-type listener() :: term().
-type opts() :: map().
-type peer_info() :: #{peer => {inet:ip_address(), inet:port_number()} | undefined, tls => undefined | map(), alpn => binary() | undefined}.
-type reset_reason() :: term().
-type send_opts() :: #{end_stream => boolean(), flush => boolean(), early_response_drain => livery_resp:drain()}.
-type send_result() :: ok | {error, closed | send_buffer_full | send_timeout | term()}.
-type stream() :: term().
Callbacks
-callback capabilities(listener()) -> capabilities().
-callback reset(stream(), reset_reason()) -> ok.
-callback send_data(stream(), iodata(), send_opts()) -> send_result().
-callback send_headers(stream(), 100..599, [{binary(), binary()}], send_opts()) -> send_result().
-callback send_informational(stream(), 100..199, [{binary(), binary()}]) -> send_result().
-callback send_trailers(stream(), [{binary(), binary()}]) -> send_result().
-callback start(Name :: atom(), listen_spec(), opts()) -> {ok, listener()} | {error, term()}.
-callback stop(listener()) -> ok.
Functions
Whether Adapter implements the optional callback Fun/Arity.
Optional features (send_full/5, send_informational/3, accept_ws/4,
accept_wt/4) are offered by implementing the callback; callers check
here instead of keeping a list of adapters.