Class: ActionDispatch::Request

Inherits:
Object
  • Object
show all
Defined in:
runtime/action_dispatch/request.rbs,
runtime/action_dispatch/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

  • .for(env, params = {}) ⇒ Request

    build a request from a Rack-shaped env hash, the test harness entry point so a controller test gets a real controller.request instead of nil.

Instance Method Summary collapse

Constructor Details

#initialize(env = nil) ⇒ void

a fresh request; the optional env hash is copied into the internal header store. Callers never receive the hash back — headers is the read-only view.

Parameters:

  • env (Hash{String => untyped}, nil) (defaults to: nil) —

    the Rack-style header bag



111
# File 'runtime/action_dispatch/request.rb', line 111

def initialize: (?Hash[String, untyped] env) -> void

Instance Attribute Details

#format ⇒ String

Returns:



48
# File 'runtime/action_dispatch/request.rbs', line 48

def format: () -> String

#host ⇒ String

Returns:



46
# File 'runtime/action_dispatch/request.rbs', line 46

def host: () -> String

#path ⇒ String

Returns:



36
# File 'runtime/action_dispatch/request.rbs', line 36

def path: () -> String

#query_string ⇒ String

Returns:



38
# File 'runtime/action_dispatch/request.rbs', line 38

def query_string: () -> String

#referer ⇒ String

Returns:



44
# File 'runtime/action_dispatch/request.rbs', line 44

def referer: () -> String

#remote_ip ⇒ String

Returns:



34
# File 'runtime/action_dispatch/request.rbs', line 34

def remote_ip: () -> String

#request_method ⇒ String

Returns:



42
# File 'runtime/action_dispatch/request.rbs', line 42

def request_method: () -> String

#script_name ⇒ String

Rack's SCRIPT_NAME: the prefix the app is mounted under, "" at the root; absolute URLs built from a request include it.

Returns:

  • (String) —

    the mount prefix, "" at the root



99
# File 'runtime/action_dispatch/request.rb', line 99

def script_name: () -> String

Class Method Details

.for(env, params = {}) ⇒ Request

build a request from a Rack-shaped env hash, the test harness entry point so a controller test gets a real controller.request instead of nil.

Parameters:

  • env (Hash{String => untyped}) —

    the Rack-shaped env the request fields are read from

  • params (Hash{String => untyped}) (defaults to: {}) —

    the request params; keys are stringified

Returns:



289
# File 'runtime/action_dispatch/request.rb', line 289

def self.for: (Hash[String, untyped] env, ?Hash[String, untyped] params) -> Request

Instance Method Details

#base_url ⇒ String

scheme + host, no path: the base an absolute URL builds on.

Returns:

  • (String) —

    the scheme and host, without a path



225
# File 'runtime/action_dispatch/request.rb', line 225

def base_url: () -> String

#body ⇒ RequestBody

Returns:



50
# File 'runtime/action_dispatch/request.rbs', line 50

def body: () -> RequestBody

#body=(value) ⇒ String

the body the transport (or the test harness) hands over is a String; what a controller reads back is the IO over it. A fresh write drops the old cursor, so a body assigned twice — the harness re-posting through one Request — starts at 0 again.

Parameters:

  • value (String) —

    the raw request body

Returns:

  • (String) —

    the stored body



155
# File 'runtime/action_dispatch/request.rb', line 155

def body=: (String) -> String

#fullpath ⇒ String

the path with its query string attached, the part an absolute URL keeps after the host.

Returns:

  • (String) —

    path, plus ?query when a query string is set



194
# File 'runtime/action_dispatch/request.rb', line 194

def fullpath: () -> String

#get? ⇒ Boolean

Returns:

  • (Boolean)


54
# File 'runtime/action_dispatch/request.rbs', line 54

def get?: () -> bool

#head? ⇒ Boolean

did the client send HEAD? It sits beside get? because the safe-request idiom is request.get? || request.head?; a filter that names the predicate must find the method.

Returns:

  • (Boolean) —

    true when the request method is HEAD



182
# File 'runtime/action_dispatch/request.rb', line 182

def head?: () -> bool

#headers ⇒ ActionDispatch::Http::Headers

the request headers as a read-only, case-insensitive view. Header names map to the internal Rack-style keys (Authorization → HTTP_AUTHORIZATION, Content-Type → CONTENT_TYPE).

Examples:

request.headers["Authorization"]

Returns:



266
# File 'runtime/action_dispatch/request.rb', line 266

def headers: () -> ActionDispatch::Http::Headers

#original_fullpath ⇒ String

Returns:



59
# File 'runtime/action_dispatch/request.rbs', line 59

def original_fullpath: () -> String

#original_url ⇒ String

the absolute URL of this request.

Returns:

  • (String) —

    scheme, host, path, and query



232
# File 'runtime/action_dispatch/request.rb', line 232

def original_url: () -> String

#params ⇒ Hash{String => Object}

the request params, keyed by String.

Returns:



273
# File 'runtime/action_dispatch/request.rb', line 273

def params: () -> Hash[String, untyped]

#params=(value) ⇒ Hash[String, untyped]

Parameters:

Returns:



70
# File 'runtime/action_dispatch/request.rbs', line 70

def params=: (Hash[String, untyped]) -> Hash[String, untyped]

#post? ⇒ Boolean

Returns:

  • (Boolean)


55
# File 'runtime/action_dispatch/request.rbs', line 55

def post?: () -> bool

#protocol ⇒ String

the scheme WITH its ://.

Returns:



218
# File 'runtime/action_dispatch/request.rb', line 218

def protocol: () -> String

#raw_post ⇒ String

the body as one String, cursor untouched.

Returns:

  • (String) —

    the whole body, cursor position ignored



169
# File 'runtime/action_dispatch/request.rb', line 169

def raw_post: () -> String

#referrer ⇒ String

Returns:



65
# File 'runtime/action_dispatch/request.rbs', line 65

def referrer: () -> String

#ssl? ⇒ Boolean

did the client connect over TLS? The server says so (HTTPS=on), or a proxy that terminated TLS in front of us says so in X-Forwarded-Proto — a load balancer or a PaaS router. The header is honored without configuration, so a request behind such a proxy builds https URLs rather than mixed-content http ones.

Returns:

  • (Boolean) —

    true when the request arrived over TLS



209
# File 'runtime/action_dispatch/request.rb', line 209

def ssl?: () -> bool

#url ⇒ String

the absolute URL, the name app code reaches for (a login filter stores it as the post-login return path). Its own method rather than an alias.

Returns:

  • (String) —

    the absolute URL, the same value as original_url



240
# File 'runtime/action_dispatch/request.rb', line 240

def url: () -> String

#user_agent ⇒ String

the User-Agent header, recorded on session rows and read by bot filters.

Returns:

  • (String) —

    the header value, "" when the request carried none



251
# File 'runtime/action_dispatch/request.rb', line 251

def user_agent: () -> String

#user_agent=(value) ⇒ String

Parameters:

Returns:



67
# File 'runtime/action_dispatch/request.rbs', line 67

def user_agent=: (String) -> String

#xhr? ⇒ Boolean

Returns:

  • (Boolean)


57
# File 'runtime/action_dispatch/request.rbs', line 57

def xhr?: () -> bool