module Lucky::RequestTypeHelpers
Overview
These helpers check HTTP headers to determine "request MIME type".
Generally the Accept
header is checked, but some check other headers, such as X-Requested-With
.
Direct including types
Defined in:
lucky/request_type_helpers.crInstance Method Summary
-
#accepts?(format : Symbol) : Bool
Check whether the request wants the passed in format
-
#ajax? : Bool
Check if the request is AJAX
-
#html? : Bool
Check if the request is HTML
-
#json? : Bool
Check if the request is JSON
-
#multipart? : Bool
Check if the request is multipart
-
#plain_text? : Bool
Check if the request is plain text
-
#xml? : Bool
Check if the request is XML
Macro Summary
-
default_format(format)
If Lucky doesn't find a format then default to the given format
Instance Method Detail
Check whether the request wants the passed in format
Check if the request is AJAX
This tests if the X-Requested-With
header is XMLHttpRequest
Check if the request is HTML
Browsers typically send vague Accept headers. Because of that this will return true
when:
- The
accepted_formats
includes:html
- And the
Accept
header is the browser default. For example `text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Check if the request is JSON
This tests if the request type is application/json
Check if the request is multipart
This tests if the Content-Type
header is multipart/form-data
Check if the request is plain text
This tests if the Accept
header type is text/plain
or
with the optional character set per W3 RFC1341 7.1
Check if the request is XML
This tests if the request type is application/xml
Macro Detail
If Lucky doesn't find a format then default to the given format
default_format :html