Request¶
MVC::Keayl::Request is a read-only wrapper around a single incoming HTTP
request. The server adapter builds one per request from the raw method, target,
headers, body, connection scheme, and peer address; controllers and middleware
then read from it through a small, stable accessor surface.
1 2 3 4 5 6 7 8 9 10 | |
Construction¶
| Named argument | Meaning |
|---|---|
:method |
HTTP verb; normalized to uppercase. Defaults to GET. |
:target |
Raw request target (path?query); split into path and query-string. |
:path |
Path, when not supplying :target. Defaults to /. |
:query-string |
Query string, when not supplying :target. Defaults to empty. |
:headers |
A hash of header names to values; names are matched case-insensitively. |
:scheme |
Connection scheme (http / https); normalized to lowercase. |
:remote-address |
The peer address reported by the connection. |
:body |
The request body: a Str, a Blob, or a Callable read lazily. |
Supplying :target takes precedence over :path / :query-string.
Method and verb predicates¶
method returns the normalized verb. Each predicate is an exact match:
1 2 3 4 5 6 7 8 | |
Path and query string¶
1 2 | |
query-params parses the query string on first access (and memoizes it).
Values are percent- and plus-decoded, and repeated keys collect into an ordered
array:
1 2 | |
Headers¶
Header lookups are case-insensitive, and multi-value headers are joined with
,:
1 2 3 | |
is-xhr reports an AJAX request (X-Requested-With: XMLHttpRequest):
1 | |
Scheme, host, port, and SSL¶
These derive from the connection and from proxy headers, so they are correct behind a reverse proxy:
1 2 3 4 5 | |
port is resolved in order: an explicit port on the host header, then
X-Forwarded-Port, then the scheme default (443 for https, 80 for http).
Remote IP¶
remote-ip prefers the first entry of X-Forwarded-For (the originating
client) and falls back to the connection's peer address:
1 2 | |
Body¶
The body is read lazily. A Callable source is invoked only on the first call
to body, and the result is memoized. A Blob is decoded as UTF-8, and a
missing body reads as the empty string:
1 | |
Reading the raw body never consumes or parses it. Structured parameter parsing (form bodies, JSON, multipart) is layered on top by the controller.
Variant¶
A variant marks a device-specific view selection. It is undefined until set, and
set-variant assigns it:
1 2 | |
detect-variant reads the User-Agent header and returns phone for a mobile
agent, tablet for an iPad-style agent, or an undefined value otherwise. Wire it
in by hand when a variant should follow the device:
1 | |
The controller uses the variant to branch respond-to blocks and to prefer a
variant template such as show.html+phone.haml.