Response¶
MVC::Keayl::Response is a mutable builder for a single outgoing HTTP response.
Controllers and middleware set the status, headers, and body on it; the server
adapter then calls finish to obtain the (status, headers, body) tuple it
hands back to the connection.
1 2 3 4 5 6 7 8 9 10 | |
Construction¶
| Named argument | Meaning |
|---|---|
:status |
HTTP status code. Defaults to 200. |
:headers |
A hash of header names to initial values. |
:body |
The initial body content. |
Status¶
status is a writable accessor:
1 2 | |
Headers¶
Header names are matched case-insensitively, and the display casing you set is preserved on output.
1 2 3 4 5 6 7 8 9 10 11 | |
Convenience accessors¶
content-type and location are getter/setter shortcuts for their headers, and
content-length reports the body's UTF-8 byte count:
1 2 3 4 5 6 7 | |
Body buffering¶
The body accumulates across write calls; the body getter returns the joined
buffer, and the body setter replaces it:
1 2 3 4 5 | |
Finalization¶
finish commits the response and returns the adapter tuple: a (status,
headers, body) list where headers is an itemized list of name => value
pairs (one pair per value, so multi-value headers like Set-Cookie stay
separate) and body is a UTF-8 Blob:
1 2 3 4 5 | |
On finalization the response supplies a default Content-Type of
text/html; charset=utf-8 when none was set, and always sets Content-Length
to the body's byte count.