class Athena::Routing::Response

Overview

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. This type is used to allow the content, status, and headers to be mutated by ART::Listeners before being returned to the client.

The #content is written all at once to the server response's IO.

Direct Known Subclasses

Defined in:

response.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(content : String | Nil = nil, status : HTTP::Status | Int32 = HTTP::Status::OK, headers : HTTP::Headers = HTTP::Headers.new) #

Creates a new response with optional content, status, and headers arguments.


[View source]

Instance Method Detail

def content : String #

Returns the contents of this response.


[View source]
def content=(content : String | Nil) #

Sets the response content.


[View source]
def etag : String | Nil #

Returns the value of the #etag header if set, otherwise nil.


[View source]
def headers : HTTP::Headers #

Returns the response headers of this response.


[View source]
def last_modified : Time | Nil #

Returns a Timerepresenting the last-modified header if set, otherwise nil.


[View source]
def last_modified=(time : Time | Nil = nil) : Nil #

Updates the last-modified header to the provided time. Removes the header if time is nil.


[View source]
def send(context : HTTP::Server::Context) : Nil #

Sends self to the client based on the provided context.

How the content gets written can be customized via an ART::Response::Writer.


[View source]
def set_etag(etag : String | Nil = nil, weak : Bool = false) : Nil #

Updates the #etag header to the provided, optionally weak, etag. Removes the header if etag is nil.


[View source]
def set_public : Nil #

Marks self as "public".

Adds the public cache-control directive and removes the private directive.


[View source]
def status : HTTP::Status #

Returns the HTTP::Status of this response.


[View source]
def status=(code : HTTP::Status | Int32) : Nil #

Sets the HTTP::Status of this response.


[View source]
def writer=(writer : ART::Response::Writer) #

[View source]