nhttp_req (nhttp v1.0.0)
View SourceAccessors for nhttp:request/0. Read fields by name, never reach into
the map directly.
The dispatch path populates a fixed shape across HTTP/1.1, HTTP/2, and
HTTP/3 (built by nhttp_lib's parsers), so the accessors here return
real values on every protocol, with no defaults and no per-protocol surprises.
scheme/1, authority/1, headers/1, method/1, path/1, and
version/1 are total. body/1, trailers/1, peer/1,
connect_protocol/1, header/2,3 return a default when the field is
absent.
Header lookup is case-insensitive on the name. The stored name is already lowercased on ingest.
Summary
Functions
Return the authority (host[:port]) component of the request URI.
Return the request body as buffered bytes, or streaming when the
handler opted into streaming-body delivery.
Return the RFC 8441 / 9220 :protocol pseudo-header value sent on
Extended CONNECT requests, or undefined if absent.
Return the value of the named header, or undefined when missing.
Names are matched case-insensitively against the request's header list.
Return the value of the named header, or Default when missing.
Names are matched case-insensitively against the request's header list.
Return the request headers as a list of {Name, Value} pairs.
Return true when the request is a WebSocket upgrade. On HTTP/1.1 this
is a GET with Upgrade: websocket. On HTTP/2 and HTTP/3 it is the
Extended CONNECT shape (method = connect,
connect_protocol = <<"websocket">>).
Return true only for the RFC 8441 / RFC 9220 Extended CONNECT WebSocket
shape (method = connect, connect_protocol = <<"websocket">>). This is
the upgrade signal used by HTTP/2 and HTTP/3 dispatch. It deliberately
ignores the HTTP/1.1 GET + Upgrade: websocket form, which is detected
upstream by the parser.
Return the request method.
Return the request path (origin-form for non-CONNECT requests).
Return the remote peer ({IP, Port}) when the dispatch path supplied
one, or undefined.
Return the request URI scheme (http | https | ws | wss).
Return the trailing header fields delivered after the request body, or
[] when there were no trailers.
Return the wire HTTP version (http1_0 | http1_1 | http2 | http3). The
dispatch path always populates it via the parser. undefined is only
returned for synthetic requests that bypass the parser (e.g. unit tests).
Functions
-spec authority(nhttp:request()) -> nhttp:authority().
Return the authority (host[:port]) component of the request URI.
-spec body(nhttp:request()) -> iodata() | streaming.
Return the request body as buffered bytes, or streaming when the
handler opted into streaming-body delivery.
-spec connect_protocol(nhttp:request()) -> binary() | undefined.
Return the RFC 8441 / 9220 :protocol pseudo-header value sent on
Extended CONNECT requests, or undefined if absent.
-spec header(nhttp:header_name(), nhttp:request()) -> nhttp:header_value() | undefined.
Return the value of the named header, or undefined when missing.
Names are matched case-insensitively against the request's header list.
-spec header(nhttp:header_name(), nhttp:request(), Default) -> nhttp:header_value() | Default.
Return the value of the named header, or Default when missing.
Names are matched case-insensitively against the request's header list.
-spec headers(nhttp:request()) -> nhttp:headers().
Return the request headers as a list of {Name, Value} pairs.
-spec is_websocket(nhttp:request()) -> boolean().
Return true when the request is a WebSocket upgrade. On HTTP/1.1 this
is a GET with Upgrade: websocket. On HTTP/2 and HTTP/3 it is the
Extended CONNECT shape (method = connect,
connect_protocol = <<"websocket">>).
-spec is_websocket_upgrade(nhttp:request()) -> boolean().
Return true only for the RFC 8441 / RFC 9220 Extended CONNECT WebSocket
shape (method = connect, connect_protocol = <<"websocket">>). This is
the upgrade signal used by HTTP/2 and HTTP/3 dispatch. It deliberately
ignores the HTTP/1.1 GET + Upgrade: websocket form, which is detected
upstream by the parser.
-spec method(nhttp:request()) -> nhttp:method().
Return the request method.
-spec path(nhttp:request()) -> binary().
Return the request path (origin-form for non-CONNECT requests).
-spec peer(nhttp:request()) -> nhttp:peer() | undefined.
Return the remote peer ({IP, Port}) when the dispatch path supplied
one, or undefined.
-spec scheme(nhttp:request()) -> nhttp:scheme().
Return the request URI scheme (http | https | ws | wss).
-spec trailers(nhttp:request()) -> nhttp:headers().
Return the trailing header fields delivered after the request body, or
[] when there were no trailers.
-spec version(nhttp:request()) -> nhttp:version() | undefined.
Return the wire HTTP version (http1_0 | http1_1 | http2 | http3). The
dispatch path always populates it via the parser. undefined is only
returned for synthetic requests that bypass the parser (e.g. unit tests).