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", "multipart/form-data"}, "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"}
.override_trusted_header(header : ATH::Request::ProxyHeader, name : String) : Nil
#
Allows overriding the header name to look for off the request for a given ATH::Request::ProxyHeader
.
In some cases a proxy might not use the exact x-forwarded-*
header name.
See the external documentation for more information.
.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"}
.set_trusted_proxies(trusted_proxies : Enumerable(String), trusted_header_set : ATH::Request::ProxyHeader) : Nil
#
Allows setting a list of trusted_proxies, and which ATH::Request::ProxyHeader
should be whitelisted.
The provided proxies are expected to be either IPv4 and/or IPv6 addresses.
The special "REMOTE_ADDRESS"
string is also supported that will map to the current request's remote address.
See the external documentation for more information.
.trusted_header_set : ATH::Request::ProxyHeader
#
Returns which ATH::Request::ProxyHeader
s have been whitelisted by the application as set via .set_trusted_proxies
, defaulting to all of them.
.trusted_proxies : Array(String)
#
Returns the list of trusted proxy IP addresses as set via .set_trusted_proxies
.
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"
#from_trusted_proxy? : Bool
#
Returns true
if this request originated from a trusted proxy.
See the external documentation for more information.
#host : String | ::Nil
#
Returns the host name the request originated from.
Supports reading from ATH::Request::ProxyHeader::FORWARDED_HOST
, falling back on the "host"
header.
See the external documentation for more information.
#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"
#port : Int32
#
Returns the port on which the request is made.
Supports reading from both ATH::Request::ProxyHeader::FORWARDED_PORT
and ATH::Request::ProxyHeader::FORWARDED_HOST
, falling back on the "host"
header, then #scheme
.
See the external documentation for more information.
ameba:disable Metrics/CyclomaticComplexity
#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.
#secure? : Bool
#
Returns true
the request was made over HTTPS, otherwise returns false
.
Supports reading from ATH::Request::ProxyHeader::FORWARDED_PROTO
.
See the external documentation for more information.