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
#
Class methods#
.mime_types(format : String) : Set(String)
#
Returns the MIME
types for the provided format.
ATH::Request.mime_types "txt" # => Set{"text/plain"}
.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"}
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
.
#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
.
#format(mime_type : String) : String | Nil
#
Returns the format for the provided mime_type.
request.format "text/plain" # => "txt"
#hostname : String | ::Nil
#
Returns the host name the request originated from.
Todo
Support reading the #hostname
from the X-Forwarded-Host
header if trusted.
#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"
#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.
#request_format=(request_format : String | Nil)
#
Sets the #request_format
to the explicitly passed format.