livery_req (livery v0.1.0)
View SourceRequest accessors and builders.
Requests flow as immutable #livery_req{} values. Adapters build
the initial value from protocol-specific events; middleware and
handlers read it via the helpers in this module and can derive a
new value for the next stage using the setters.
Summary
Functions
Adapter module that produced this request.
Append a header even if one with this name exists.
Authority (host:port), as the client sent it.
Look up a binding, or undefined.
Look up a binding, falling back to Default.
Map of path parameters captured by the router.
Body shape: empty, {buffered, IoData}, or {stream, Reader}.
Remove every header with this name.
The tag of the disconnect message delivered to a request worker.
Engine pid for this connection (adapter-specific).
True if the header is present at least once.
First value for a header, or undefined.
First value for a header, falling back to Default.
All request headers in wire order, names lowercased.
Return all values associated with a header name.
Full meta map.
Look up a meta key, or undefined.
Look up a meta key, falling back to Default.
HTTP method, uppercase binary (e.g. <<"GET">>).
Construct a request from a map of fields.
Register a cancel callback to run when the client disconnects.
Decoded path portion of the request URI.
Peer address and port if the adapter knows it.
Wire protocol of the request: h1, h2, or h3.
Raw query string (everything after ?, no leading ?).
Request id set by livery_request_id or user code.
URL scheme: typically <<"http">> or <<"https">>.
Replace the bindings map (used by the router).
Replace the body field on the request.
Replace (or insert) a header.
Set a meta key. Used by middleware to thread state to handlers.
Set the request id field. Used by livery_request_id.
Monotonic-time timestamp set by livery_req_proc on entry.
Adapter-specific stream handle.
TLS info map for HTTPS requests; undefined for plain HTTP.
Types
-type header_name() :: binary().
-type header_value() :: binary().
-type req() :: #livery_req{protocol :: h1 | h2 | h3, method :: binary(), scheme :: binary(), authority :: binary(), path :: binary(), raw_query :: binary(), bindings :: #{binary() => binary()}, headers :: [{binary(), binary()}], peer :: {inet:ip_address(), inet:port_number()} | undefined, tls :: undefined | map(), body :: empty | {buffered, iodata()} | {stream, term()}, adapter :: module() | undefined, stream :: term(), engine_pid :: pid() | undefined, notifier_pid :: pid() | undefined, disc_ref :: reference() | undefined, req_id :: binary(), started_at :: integer() | undefined, meta :: map()}.
Functions
Adapter module that produced this request.
-spec append_header(header_name(), header_value(), req()) -> req().
Append a header even if one with this name exists.
Authority (host:port), as the client sent it.
Look up a binding, or undefined.
Look up a binding, falling back to Default.
Map of path parameters captured by the router.
Body shape: empty, {buffered, IoData}, or {stream, Reader}.
The Reader is opaque; drain it with livery_body:read/2.
-spec delete_header(header_name(), req()) -> req().
Remove every header with this name.
-spec disconnect_tag() -> livery_disconnect.
The tag of the disconnect message delivered to a request worker.
A handler in a receive loop matches
{livery_disconnect, _Ref, _Reason}. This helper returns the tag
atom (livery_disconnect) for guard-style matching.
Engine pid for this connection (adapter-specific).
-spec has_header(header_name(), req()) -> boolean().
True if the header is present at least once.
-spec header(header_name(), req()) -> header_value() | undefined.
First value for a header, or undefined.
-spec header(header_name(), req(), Default) -> header_value() | Default.
First value for a header, falling back to Default.
-spec headers(req()) -> [{header_name(), header_value()}].
All request headers in wire order, names lowercased.
-spec headers_all(header_name(), req()) -> [header_value()].
Return all values associated with a header name.
HTTP header names may appear more than once in H1 and H2; this returns them in wire order.
Full meta map.
Look up a meta key, or undefined.
Look up a meta key, falling back to Default.
HTTP method, uppercase binary (e.g. <<"GET">>).
Construct a request from a map of fields.
Intended for adapters. Unspecified fields fall back to defaults on the record.
Register a cancel callback to run when the client disconnects.
Fun is a 0-arity function (e.g. fun() -> my_llm:cancel(Ref) end).
If the client resets the stream or closes the connection before the
request finishes, Fun is run exactly once in a fresh process, even
if the handler is blocked in a NIF. It never runs on normal
completion. Returns ok immediately; a no-op on adapters without a
real connection (e.g. the test adapter).
A handler that runs its own receive loop can instead match the
{livery_disconnect, _Ref, _Reason} message delivered to it; see
disconnect_tag/0.
Decoded path portion of the request URI.
-spec peer(req()) -> {inet:ip_address(), inet:port_number()} | undefined.
Peer address and port if the adapter knows it.
-spec protocol(req()) -> h1 | h2 | h3.
Wire protocol of the request: h1, h2, or h3.
Raw query string (everything after ?, no leading ?).
Request id set by livery_request_id or user code.
URL scheme: typically <<"http">> or <<"https">>.
Replace the bindings map (used by the router).
Replace the body field on the request.
-spec set_header(header_name(), header_value(), req()) -> req().
Replace (or insert) a header.
Set a meta key. Used by middleware to thread state to handlers.
Set the request id field. Used by livery_request_id.
Monotonic-time timestamp set by livery_req_proc on entry.
Adapter-specific stream handle.
TLS info map for HTTPS requests; undefined for plain HTTP.