roadrunner_http (roadrunner v0.2.3)
View SourceProtocol-version-agnostic HTTP semantics shared by HTTP/1.1
(roadrunner_http1) and HTTP/2 (roadrunner_http2_*) modules.
What lives here is RFC 9110 semantics — types and helpers whose
meaning doesn't depend on wire framing — not RFC 9112 syntax.
The HTTP/1.1 wire codec (request-line / header / chunked
parsers, status-line + CRLF response encoder) stays in
roadrunner_http1. HTTP/2 frame codec + HPACK live in their
own modules.
Items here:
- Header list shape:
[{binary(), binary()}]. - HTTP status codes:
100..599and the redirect subset. - Protocol version tuple:
{Major, Minor}. - IMF-fixdate formatter (
http_date_now/0for the current time,format_http_date/1for an arbitrary posix timestamp) for theDateresponse header per RFC 9110 §5.6.7 and theLast-Modifiedresponse header used by the static handler.
roadrunner_http1 and roadrunner_req re-export the primitive
types as aliases so existing callers keep compiling unchanged.
The request map shape lives in roadrunner_req alongside the
accessors that operate on it.
Summary
Functions
Inject the framework's automatic response headers for an HTTP/1 or
HTTP/2 (TCP) response: Date always (RFC 9110 §6.6.1) plus Alt-Svc
advertising the listener's HTTP/3 endpoint (RFC 7838) when it co-serves
h3 on a fixed port (proto_opts carries the precomputed value only
then). HTTP/3 responses use with_date/1 directly — a client already
on h3 needs no Alt-Svc.
Format a posix timestamp (seconds since epoch) as an IMF-fixdate
per RFC 9110 §5.6.7. Same shape as http_date_now/0 but for an
explicit timestamp — used by the static file handler to emit the
Last-Modified header for a file's mtime.
Format the current UTC time as an IMF-fixdate per RFC 9110 §5.6.7
— the canonical HTTP Date header format, e.g.
Sun, 06 Nov 1994 08:49:37 GMT. Used by the dispatch layer to
auto-inject the Date response header per RFC 9110 §6.6.1.
Inject a Date response header (RFC 9110 §6.6.1) unless the handler
already set one. Shared by the HTTP/1, HTTP/2, and HTTP/3 response
paths so every response carries Date from the one cached clock
(http_date_now/0). RFC 9110 makes Date a MUST on 2xx/3xx/4xx and
a MAY on 1xx/5xx, so injecting it unconditionally is conformant.
Types
Functions
Inject the framework's automatic response headers for an HTTP/1 or
HTTP/2 (TCP) response: Date always (RFC 9110 §6.6.1) plus Alt-Svc
advertising the listener's HTTP/3 endpoint (RFC 7838) when it co-serves
h3 on a fixed port (proto_opts carries the precomputed value only
then). HTTP/3 responses use with_date/1 directly — a client already
on h3 needs no Alt-Svc.
Format a posix timestamp (seconds since epoch) as an IMF-fixdate
per RFC 9110 §5.6.7. Same shape as http_date_now/0 but for an
explicit timestamp — used by the static file handler to emit the
Last-Modified header for a file's mtime.
-spec http_date_now() -> binary().
Format the current UTC time as an IMF-fixdate per RFC 9110 §5.6.7
— the canonical HTTP Date header format, e.g.
Sun, 06 Nov 1994 08:49:37 GMT. Used by the dispatch layer to
auto-inject the Date response header per RFC 9110 §6.6.1.
Built via direct bit-syntax binary construction rather than
io_lib:format/2 because the shape is fixed (RFC 9110 mandates
exact widths and the day/month abbreviations) and this function
runs on the response hot path.
Cached via persistent_term keyed by the current Posix second:
the formatted binary is identical for every request that lands in
the same second, so we recompute it only when the second ticks
over. Updates are racy on the second boundary (multiple processes
may put the same value), but each put writes the same binary so
the race is benign.
Inject a Date response header (RFC 9110 §6.6.1) unless the handler
already set one. Shared by the HTTP/1, HTTP/2, and HTTP/3 response
paths so every response carries Date from the one cached clock
(http_date_now/0). RFC 9110 makes Date a MUST on 2xx/3xx/4xx and
a MAY on 1xx/5xx, so injecting it unconditionally is conformant.