class Marten::HTTP::Request

Overview

Represents an HTTP request processed by Marten.

When a page is request, Marten creates a Marten::HTTP::Request that gives access to all the information and metadata of the incoming request.

Included Modules

Defined in:

marten/http/request.cr
marten/spec/ext/http/request.cr
marten/template/ext/http/request.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(method : String, resource : String, headers : ::HTTP::Headers | Nil = nil, body : String | Bytes | IO | Nil = nil, version = "HTTP/1.1") #

[View source]
def self.new(request : ::HTTP::Request) #

[View source]

Instance Method Detail

def accepted_media_types : Array(MIME::MediaType) #

Returns an array of the media types accepted by the request.


[View source]
def accepts?(media_type : String) #

Returns true if the passed media type is accepted by the request.


[View source]
def body : String #

Returns the raw body of the request as a string.


[View source]
def content_security_policy : ContentSecurityPolicy | Nil #

Returns the content security policy assigned with the request.


[View source]
def content_security_policy=(content_security_policy : ContentSecurityPolicy | Nil) #

Allows to assign a new content security policy to the request (or reset it if the passed value is nil).


[View source]
def content_security_policy_nonce #

Returns the value of a Content-Security-Policy nonce associated with the request.


[View source]
def cookies #

Returns the cookies associated with the request.


[View source]
def data : Params::Data #

Returns the parsed request data.


[View source]
def delete? #

Returns true if the request is a DELETE.


[View source]
def flash #

Returns the flash store for the considered request.

If no flash store was previously set (for example if the flash middleware is not used), a NilAssertionError exception will be raised.


[View source]
def flash=(flash_store : FlashStore) #

Allows to set the flash store for the request.


[View source]
def flash? #

Returns true if the flash store was properly set for the considered request.


[View source]
def full_path : String #

Returns the path including the GET parameters if applicable.


[View source]
def get? #

Returns true if the request is a GET.


[View source]
def head? #

Returns true if the request is a HEAD.


[View source]
def headers : Headers #

Returns the HTTP headers embedded in the request.


[View source]
def host : String #

Returns the host associated with the considered request.


[View source]
def method : String #

Returns a string representation of HTTP method that was used in the request.

The returned method name (eg. "GET" or "POST") is completely uppercase.


[View source]
def options? #

Returns true if the request is an OPTIONS.


[View source]
def patch? #

Returns true if the request is a PATCH.


[View source]
def path : String #

Returns the request path as a string.

Only the path of the request is included (without scheme or domain).


[View source]
def port : String | Nil #

Returns the port associated with the considered request.


[View source]
def post? #

Returns true if the request is a POST.


[View source]
def put? #

Returns true if the request is a PUT.


[View source]
def query_params : Params::Query #

Returns the HTTP GET parameters embedded in the request.


[View source]
def scheme : String #

Returns the scheme of the request (either "http" or "https").


[View source]
def secure? #

Returns true if the request is secure (if it is an HTTPS request).


[View source]
def session #

Returns the session store for the considered request.

If no session store was previously set (for example if the session middleware is not set), a NilAssertionError exception will be raised.


[View source]
def session=(session_store : Session::Store::Base) #

Allows to set the session store for the request.


[View source]
def session? #

Returns true if the session store was properly set for the considered request.


[View source]
def trace? #

Returns true if the request is a TRACE.


[View source]