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

Macro Summary

Instance Method Summary

Macro Detail

macro default_format(format) #

If Lucky doesn't find a format then default to the given format

default_format :html

[View source]

Instance Method Detail

def accepts?(format : Symbol) : Bool #

Check whether the request wants the passed in format


[View source]
def ajax? : Bool #

Check if the request is AJAX

This tests if the X-Requested-With header is XMLHttpRequest


[View source]
def html? : Bool #

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

[View source]
def json? : Bool #

Check if the request is JSON

This tests if the request type is application/json


[View source]
def multipart? : Bool #

Check if the request is multipart

This tests if the Content-Type header is multipart/form-data


[View source]
def plain_text? : Bool #

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


[View source]
def xml? : Bool #

Check if the request is XML

This tests if the request type is application/xml


[View source]