Skip to content

class Athena::Framework::Request
inherits Reference #

Wraps an HTTP::Request instance to provide additional functionality.

Forwards all additional methods to the wrapped HTTP::Request instance.

Constants#

FORMATS = {"atom" => Set {"application/atom+xml"}, "css" => Set {"text/css"}, "csv" => Set {"text/csv"}, "form" => Set {"application/x-www-form-urlencoded"}, "html" => Set {"text/html", "application/xhtml+xml"}, "js" => Set {"application/javascript", "application/x-javascript", "text/javascript"}, "json" => Set {"application/json", "application/x-json"}, "jsonld" => Set {"application/ld+json"}, "rdf" => Set {"application/rdf+xml"}, "rss" => Set {"application/rss+xml"}, "txt" => Set {"text/plain"}, "xml" => Set {"text/xml", "application/xml", "application/x-xml"}}#

Represents the supported built in formats; mapping the format name to its valid MIME type(s).

Additional formats may be registered via .register_format.

Constructors#

.new(method : String, path : String, headers : HTTP::Headers | Nil = nil, body : String | Bytes | IO | Nil = nil, version : String = "HTTP/1.1") : self#

View source

.new(request : self) : self#

View source

.new(request : HTTP::Request)#

View source

Class methods#

.mime_types(format : String) : Set(String)#

Returns the MIME types for the provided format.

ATH::Request.mime_types "txt" # => Set{"text/plain"}
View source

.register_format(format : String, mime_types : Indexable(String)) : Nil#

Registers the provided format with the provided mime_types. Can also be used to change the mime_types supported for an existing format.

ATH::Request.register_format "some_format", {"some/mimetype"}
View source

Methods#

#action : ATH::ActionBase#

The ATH::Action object associated with this request.

Will only be set if a route was able to be resolved as part of ATH::Listeners::Routing.

View source

#action? : ATH::ActionBase | ::Nil#

The ATH::Action object associated with this request.

Will only be set if a route was able to be resolved as part of ATH::Listeners::Routing.

View source

#attributes : ATH::ParameterBag#

View source

#format(mime_type : String) : String | Nil#

Returns the format for the provided mime_type.

request.format "text/plain" # => "txt"
View source

#hostname : String | ::Nil#

Returns the host name the request originated from.

Todo

Support reading the #hostname from the X-Forwarded-Host header if trusted.

View source

#mime_type(format : String) : String | Nil#

Returns the first MIME type for the provided format if defined, otherwise returns nil.

request.mime_type "txt" # => "text/plain"
View source

#request : HTTP::Request#

Returns the raw wrapped HTTP::Request instance.

View source

#request_data#

Returns an HTTP::Params instance based on this request's form data body.

View source

#request_format(default : String | Nil = "json") : String | Nil#

Returns the format for this request.

First checks if a format was explicitly set via #request_format=. Next, will check for the _format request #attributes, finally falling back on the provided default.

View source

#request_format=(request_format : String | Nil)#

Sets the #request_format to the explicitly passed format.

View source

#safe? : Bool#

Returns true if this request's #method is safe. Otherwise returns false.

View source