123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::TestRequest

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
ActionController::TestRequest
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Request, Rack::Request
Instance Chain:
Inherits: ActionDispatch::Request
Defined in: actionpack/lib/action_dispatch/testing/test_request.rb

Constant Summary

Http::Cache::Request - Included

HTTP_IF_MODIFIED_SINCE, HTTP_IF_NONE_MATCH

Http::MimeNegotiation - Included

BROWSER_LIKE_ACCEPTS

Http::Parameters - Included

PARAMETERS_KEY

Http::FilterParameters - Included

KV_RE, PAIR_RE

Http::URL - Included

HOST_REGEXP, IP_HOST_REGEXP, PROTOCOL_REGEXP

Request - Inherited

ENV_METHODS, HTTP_METHODS, HTTP_METHOD_LOOKUP, LOCALHOST, RFC2518, RFC2616, RFC3253, RFC3648, RFC3744, RFC4791, RFC5323, RFC5789

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

Request - Inherited

#delete?

Is this a DELETE request? Equivalent to request.request_method_symbol == :delete.

#form_data?,
#get?

Is this a GET (or HEAD) request? Equivalent to request.request_method_symbol == :get.

#head?

Is this a HEAD request? Equivalent to request.request_method_symbol == :head.

#ignore_accept_header,
#local?

True if the request came from localhost, 127.0.0.1.

#patch?

Is this a PATCH request? Equivalent to request.request_method == :patch.

#post?

Is this a POST request? Equivalent to request.request_method_symbol == :post.

#put?

Is this a PUT request? Equivalent to request.request_method_symbol == :put.

#request_method

Returns the HTTP method that the application should see.

#session_options=,
#xhr?
#xml_http_request?

Returns true if the “X-Requested-With” header contains “XMLHttpRequest” (case-insensitive), which may need to be manually added depending on the choice of JavaScript libraries and frameworks.

Http::URL - Included

#standard_port

Returns the standard port number for this request's protocol.

#standard_port?

Returns whether this request is using the standard port.

#tld_length

Http::Parameters - Included

#path_parameters

Returns a hash with the parameters used to form the path of the request.

Http::MimeNegotiation - Included

#formats,
#formats=

Sets the formats by string extensions.

#variant,
#variant=

Sets the variant for template.

Instance Method Summary

Request - Inherited

#authorization

Returns the authorization header regardless of whether it was specified directly or through one of the proxy alternatives.

#body

The request body is an IO input stream.

#check_path_parameters!,
#content_length

Returns the content length of the request as an integer.

#cookie_jar,
#deep_munge

Extracted into Request::Utils.deep_munge, but kept here for backwards compatibility.

#flash

Access the contents of the flash.

#fullpath

Returns the ::String full path including params of the last URL requested.

#GET

Override Rack's GET method to support indifferent access.

#headers

Provides access to the request's HTTP headers, for example:

#ip, #key?,
#media_type

The ::String MIME type of the request.

#method

Returns the original value of the environment's REQUEST_METHOD, even if it was overridden by middleware.

#method_symbol

Returns a symbol form of the #method

#original_fullpath

Returns a ::String with the last requested path including their params.

#original_url

Returns the original request URL as a ::String.

#POST

Override Rack's POST method to support indifferent access.

#query_parameters

Alias for Request#GET.

#raw_post

Read the request body.

#remote_ip

Originating IP address, usually set by the RemoteIp middleware.

#request_method_symbol

Returns a symbol form of the #request_method

#request_parameters

Alias for Request#POST.

#reset_session

TODO This should be broken apart into AD::Request::Session and probably be included by the session middleware.

#server_software

Returns the lowercase name of the HTTP server software.

#uuid

Returns the unique request id, which is based on either the X-Request-Id header that can be generated by a firewall, load balancer, or web server or by the RequestId middleware (which sets the action_dispatch.request_id environment variable).

Http::URL - Included

#domain

Returns the domain part of a host, such as “rubyonrails.org” in “www.rubyonrails.org”.

#host

Returns the host for this request, such as example.com.

#host_with_port

Returns a host:port string for this request, such as “example.com” or “example.com:8080”.

#initialize,
#optional_port

Returns a number port suffix like 8080 if the port number of this request is not the default HTTP port 80 or HTTPS port 443.

#port

Returns the port number of this request as an integer.

#port_string

Returns a string port suffix, including colon, like “:8080” if the port number of this request is not the default HTTP port 80 or HTTPS port 443.

#protocol

Returns 'https://' if this is an SSL request and 'http://' otherwise.

#raw_host_with_port

Returns the host for this request, such as “example.com”.

#server_port,
#subdomain

Returns all the subdomains as a string, so "dev.www" would be returned for “dev.www.rubyonrails.org”.

#subdomains

Returns all the subdomains as an array, so ["dev", "www"] would be returned for “dev.www.rubyonrails.org”.

#url

Returns the complete URL used for this request.

Http::FilterParameters - Included

#filtered_env

Return a hash of request.env with all sensitive data replaced.

#filtered_parameters

Return a hash of parameters with all sensitive data replaced.

#filtered_path

Reconstructed a path with all sensitive GET parameters replaced.

#initialize

Http::Parameters - Included

#parameters

Returns both GET and POST parameters in a single hash.

#params
#symbolized_path_parameters

Http::MimeNegotiation - Included

#accepts

Returns the accepted MIME type for the request.

#content_mime_type

The MIME type of the HTTP request, such as Mime::XML.

#content_type,
#format

Returns the MIME type for the format used in the request.

#format=

Sets the format by string extension, which can be used to force custom formats that are not controlled by the extension.

#negotiate_mime

Receives an array of mimes and return the first user sent mime that matches the order array.

Http::Cache::Request - Included

#etag_matches?,
#fresh?

Check response freshness (Last-Modified and ETag) against request If-Modified-Since and If-None-Match conditions.

#if_modified_since, #if_none_match, #if_none_match_etags, #not_modified?

Constructor Details

.new(env = {}) ⇒ TestRequest

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 12

def self.new(env = {})
  super
end

#initialize(env = {}) ⇒ TestRequest

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 16

def initialize(env = {})
  env = Rails.application.env_config.merge(env) if defined?(Rails.application) && Rails.application
  super(default_env.merge(env))
end

Instance Attribute Details

#accept=(mime_types) (writeonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 61

def accept=(mime_types)
  @env.delete('action_dispatch.request.accepts')
  @env['HTTP_ACCEPT'] = Array(mime_types).collect { |mime_type| mime_type.to_s }.join(",")
end

#action=(action_name) (writeonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 41

def action=(action_name)
  path_parameters[:action] = action_name.to_s
end

#host=(host) (writeonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 25

def host=(host)
  @env['HTTP_HOST'] = host
end

#if_modified_since=(last_modified) (writeonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 45

def if_modified_since=(last_modified)
  @env['HTTP_IF_MODIFIED_SINCE'] = last_modified
end

#if_none_match=(etag) (writeonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 49

def if_none_match=(etag)
  @env['HTTP_IF_NONE_MATCH'] = etag
end

#path=(path) (writeonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 37

def path=(path)
  @env['PATH_INFO'] = path
end

#port=(number) (writeonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 29

def port=(number)
  @env['SERVER_PORT'] = number.to_i
end

#remote_addr=(addr) (writeonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 53

def remote_addr=(addr)
  @env['REMOTE_ADDR'] = addr
end

#request_method=(method) (writeonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 21

def request_method=(method)
  @env['REQUEST_METHOD'] = method.to_s.upcase
end

#request_uri=(uri) (writeonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 33

def request_uri=(uri)
  @env['REQUEST_URI'] = uri
end

#user_agent=(user_agent) (writeonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 57

def user_agent=(user_agent)
  @env['HTTP_USER_AGENT'] = user_agent
end

Instance Method Details

#cookies

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 68

def cookies
  @cookies ||= {}.with_indifferent_access
end

#rack_cookies

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 66

alias :rack_cookies :cookies