final case class Response(status: Int, headers: Seq[(String, Url | String)], body: Body, session: Option[Session] = ...)
A response, as a value.
The status is a plain Int, reached through the named constructors below, because a framework that cannot return 418 is a framework people work around. Headers are an ordered Seq that permits duplicates, deliberately asymmetric with the request's Map: writing wants order and repetition, Set-Cookie being both, while reading wants keyed lookup. The session is carried as a value beside them rather than pre-rendered into one, because signing needs the secret and the handler does not have it.
The first value carried under this name, as it goes on the wire.
The first value carried under this name, as it goes on the wire.
A header value is a Url or a String, and every reader wants the one spelling, so the flattening lives here rather than at each site that has to ask what a Location says.
Sets a cookie: one more Set-Cookie header, rendered by the cookie itself. The session cookie never goes through here from user code; it is written once, from session, after dispatch.
Sets a cookie: one more Set-Cookie header, rendered by the cookie itself. The session cookie never goes through here from user code; it is written once, from session, after dispatch.
Appends a header, keeping any header of the same name that is already there.
Appends a header, keeping any header of the same name that is already there.
The value is the same Url | String the header list carries, so a Location that still travels with its mount can be added to a response that already exists. Widened rather than overloaded, because String conforms to the union and every call site that passes one keeps compiling and keeps meaning a finished value.
The session this response keeps: usually the request's, amended. None, the default, keeps the request's session exactly as the handler saw it, so a handler that only reads costs nothing. The cookie itself is written once, after dispatch, and only when the session changed.
The session this response keeps: usually the request's, amended. None, the default, keeps the request's session exactly as the handler saw it, so a handler that only reads costs nothing. The cookie itself is written once, after dispatch, and only when the session changed.