class Athena::HTTP::Response
inherits Reference
#
Represents an HTTP response that should be returned to the client.
Contains the content, status, and headers that should be applied to the actual HTTP::Server::Response.
The #content is written all at once to the server response's IO.
Direct known subclasses
Athena::HTTP::BinaryFileResponse
Athena::HTTP::RedirectResponse
Athena::HTTP::StreamedResponse
Constructors#
.new(content : String | Nil = nil, status : ::HTTP::Status | Int32 = ::HTTP::Status::OK, headers : ::HTTP::Headers | AHTTP::Response::Headers = AHTTP::Response::Headers.new)#
Creates a new response with optional content, status, and headers arguments.
Methods#
#expires : Time | ::Nil#
Returns a Time representing the expires header if set, otherwise nil.
An invalid expires header value, such as 0 or -1, is treated as being in the past.
#expires=(time : Time | Nil) : self#
Updates the expires header to the provided time.
Removes the header if time is nil.
#last_modified : Time | ::Nil#
Returns a Timerepresenting the last-modified header if set, otherwise nil.
#last_modified=(time : Time | Nil = nil) : self#
Updates the last-modified header to the provided time.
Removes the header if time is nil.
#max_age : Int32 | ::Nil#
Returns the number of seconds after which the response should no longer be considered fresh, or nil if unknown.
Uses the s-maxage or max-age cache-control directive if present, otherwise the difference between the expires and date headers.
#max_age=(value : Int32) : self#
Sets the number of seconds after which the response should no longer be considered fresh, via the max-age cache-control directive.
#redirect?(location : String | Nil = nil) : Bool#
Returns true if this response is a redirect, optionally to the provided location.
Otherwise, returns false.
#send(request : AHTTP::Request, response : ::HTTP::Server::Response) : self#
Sends self to the client based on the provided context.
How the content gets written can be customized via an AHTTP::Response::Writer.
#set_etag(etag : String | Nil = nil, weak : Bool = false) : self#
Updates the etag header to the provided, optionally weak, etag.
Removes the header if etag is nil.
#set_private : self#
Marks self as "private".
Adds the private cache-control directive and removes the public directive.
#set_public : self#
Marks self as "public".
Adds the public cache-control directive and removes the private directive.
#status=(code : ::HTTP::Status | Int32) : self#
Sets the ::HTTP::Status of this response.