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", "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#

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

.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.

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

.set_trusted_hosts(host_patterns : Array(Regex)) : Nil#

Allows setting a list of host_patterns used to whitelist the allowed hostnames of requests. If there is at least one pattern defined, requests whose hostname does NOT match any of the patterns, will receive a 400 response.

See ATH::Bundle:Schema#trusted_hosts for more information.

View source

.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.

View source

.trusted_header_set : ATH::Request::ProxyHeader#

Returns which ATH::Request::ProxyHeaders have been whitelisted by the application as set via .set_trusted_proxies, defaulting to all of them.

View source

.trusted_host_patterns : Array(Regex)#

Returns the list of trusted host patterns set via .set_trusted_hosts.

View source

.trusted_proxies : Array(String)#

Returns the list of trusted proxy IP addresses as set via .set_trusted_proxies.

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

#content_type_format : String | ::Nil#

Returns the Format of the request based on its content-type header, or nil if the header is missing.

View source

#files : Hash(String, Array(ATH::UploadedFile))#

If enabled, Athena will populate this hash with files from the request body of multipart/form-data requests.

The keys of the hash map to the name attribute of the related file input control. The value of the hash is an array in order to handle multi-file uploads using the same name.

View source

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

Returns the format for the provided mime_type.

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

#from_trusted_proxy? : Bool#

Returns true if this request originated from a trusted proxy.

See the external documentation for more information.

View source

#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.

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

#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

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

#scheme : String#

Returns the scheme of this request.

View source

#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.

View source