Class: ActionDispatch::TestRequest
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Subclasses:
ActionController::TestRequest, ActionCable::Connection::TestRequest
|
|
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Request
|
|
|
Instance Chain:
self,
Request,
Flash::RequestMethods,
Rack::Request::Env,
PermissionsPolicy::Request,
ContentSecurityPolicy::Request,
Http::URL,
Http::FilterParameters,
Http::Parameters,
Http::MimeNegotiation,
Http::Cache::Request,
Rack::Request::Helpers
|
|
| Inherits: |
ActionDispatch::Request
|
| Defined in: | actionpack/lib/action_dispatch/testing/test_request.rb |
Constant Summary
-
DEFAULT_ENV =
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 10Rack::MockRequest.env_for("/", "HTTP_HOST" => "test.host".b, "REMOTE_ADDR" => "0.0.0.0".b, "HTTP_USER_AGENT" => "Rails Testing".b, )
Http::Cache::Request - Included
HTTP_IF_MODIFIED_SINCE, HTTP_IF_NONE_MATCH
Http::MimeNegotiation - Included
BROWSER_LIKE_ACCEPTS, RESCUABLE_MIME_FORMAT_ERRORS
Http::Parameters - Included
DEFAULT_PARSERS, PARAMETERS_KEY
Http::URL - Included
HOST_REGEXP, IP_HOST_REGEXP, PROTOCOL_REGEXP
ContentSecurityPolicy::Request - Included
NONCE, NONCE_DIRECTIVES, NONCE_GENERATOR, POLICY, POLICY_REPORT_ONLY
PermissionsPolicy::Request - Included
Request - Inherited
ENV_METHODS, HTTP_METHODS, HTTP_METHOD_LOOKUP, LOCALHOST, RFC2518, RFC2616, RFC3253, RFC3648, RFC3744, RFC4791, RFC5323, RFC5789
Class Attribute Summary
Request - Inherited
| .ignore_accept_header, | |
| .parameter_parsers | Returns the parameter parsers. |
Class Method Summary
-
.create(env = {})
Create a new test request with default
envvalues.
Request - Inherited
Instance Attribute Summary
- #accept=(mime_types) writeonly
- #action=(action_name) writeonly
- #host=(host) writeonly
- #if_modified_since=(last_modified) writeonly
- #if_none_match=(etag) writeonly
- #path=(path) writeonly
- #port=(number) writeonly
- #remote_addr=(addr) writeonly
- #request_method=(method) writeonly
- #request_uri=(uri) writeonly
- #user_agent=(user_agent) writeonly
Request - Inherited
| #form_data? | Determine whether the request body contains form-data by checking the request |
| #ignore_accept_header, | |
| #local? | True if the request came from localhost, 127.0.0.1, or ::1. |
| #remote_ip | |
| #remote_ip=, | |
| #request_id | Returns the unique request id, which is based on either the |
| #request_method | Returns the HTTP method that the application should see. |
| #request_parameters | Alias for Request#POST. |
| #request_parameters=, | |
| #route_uri_pattern | Returns the URI pattern of the matched route for the request, using the same format as ‘bin/rails routes`: |
| #session_options=, | |
| #uuid | Alias for Request#request_id. |
| #xhr? | Alias for Request#xml_http_request?. |
| #xml_http_request? | Returns true if the |
Flash::RequestMethods - Included
PermissionsPolicy::Request - Included
ContentSecurityPolicy::Request - Included
Http::URL - Included
| #secure_protocol, | |
| #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. |
| #should_apply_vary_header?, #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 |
| #commit_csrf_token, #commit_flash, | |
| #content_length | Returns the content length of the request as an integer. |
| #controller_class, #controller_class_for, | |
| #fullpath | Returns the |
| #GET | Override Rack’s GET method to support indifferent access. |
| #headers | Provides access to the request’s HTTP headers, for example: |
| #http_auth_salt, | |
| #ip | Returns the IP address of client as a |
| #key? | Returns true if the request has a header matching the given key parameter. |
| #logger, | |
| #media_type | The |
| #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 |
| #original_fullpath | Returns a |
| #original_url | Returns the original request URL as a |
| #POST | Override Rack’s POST method to support indifferent access. |
| #query_parameters | Alias for Request#GET. |
| #raw_post | Read the request body. |
| #request_method_symbol | Returns a symbol form of the |
| #reset_csrf_token, #reset_session, | |
| #send_early_hints | Early Hints is an HTTP/2 status code that indicates hints to help a client start making preparations for processing the final response. |
| #server_software | Returns the lowercase name of the HTTP server software. |
ContentSecurityPolicy::Request - Included
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 |
| #raw_host_with_port | Returns the host and port for this request, such as “example.com:8080”. |
| #server_port | Returns the requested port, such as 8080, based on SERVER_PORT. |
| #subdomain | Returns all the subdomains as a string, so |
| #subdomains | Returns all the subdomains as an array, so |
| #url | Returns the complete URL used for this request. |
Http::FilterParameters - Included
| #filtered_env | Returns a hash of request.env with all sensitive data replaced. |
| #filtered_parameters | Returns a hash of parameters with all sensitive data replaced. |
| #filtered_path | Reconstructs a path with all sensitive GET parameters replaced. |
| #initialize, | |
| #parameter_filter | Returns the |
Http::Parameters - Included
| #parameters | Returns both GET and POST parameters in a single hash. |
| #params | Alias for Http::Parameters#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). |
| #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 | Returns the first MIME type that matches the provided array of MIME types. |
Http::Cache::Request - Included
| #etag_matches?, | |
| #fresh? | Check response freshness (‘Last-Modified` and ETag) against request |
| #if_modified_since, #if_none_match, #if_none_match_etags, #not_modified? | |
Constructor Details
This class inherits a constructor from ActionDispatch::Request
Class Method Details
.create(env = {})
Create a new test request with default env values.
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 17
def self.create(env = {}) env = Rails.application.env_config.merge(env) if defined?(Rails.application) && Rails.application env["rack.request.cookie_hash"] ||= {}.with_indifferent_access new(default_env.merge(env)) end
Instance Attribute Details
#accept=(mime_types) (writeonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 68
def accept=(mime_types) delete_header("action_dispatch.request.accepts") set_header("HTTP_ACCEPT", Array(mime_types).collect(&:to_s).join(",")) end
#action=(action_name) (writeonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 48
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 32
def host=(host) set_header("HTTP_HOST", host) end
#if_modified_since=(last_modified) (writeonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 52
def if_modified_since=(last_modified) set_header("HTTP_IF_MODIFIED_SINCE", last_modified) end
#if_none_match=(etag) (writeonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 56
def if_none_match=(etag) set_header("HTTP_IF_NONE_MATCH", etag) end
#path=(path) (writeonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 44
def path=(path) set_header("PATH_INFO", path) end
#port=(number) (writeonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 36
def port=(number) set_header("SERVER_PORT", number) end
#remote_addr=(addr) (writeonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 60
def remote_addr=(addr) set_header("REMOTE_ADDR", addr) end
#request_method=(method) (writeonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 28
def request_method=(method) super(method.to_s.upcase) end
#request_uri=(uri) (writeonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 40
def request_uri=(uri) set_header("REQUEST_URI", uri) end
#user_agent=(user_agent) (writeonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 64
def user_agent=(user_agent) set_header("HTTP_USER_AGENT", user_agent) end