Class

ActionController::Request

Inheritance
< Rack::Request < Object

Constants

Name   Description
HTTP_METHODS = %w(get head put post delete options)
HTTP_METHOD_LOOKUP = HTTP_METHODS.inject({}) { |h, m| h[m] = h[m.upcase] = m.to_sym;
TRUSTED_PROXIES = /^127\.0\.0\.1$|^(10|172\.(1[6-9]|2[0-9]|30|31)|192\.168)\./i Which IP addresses are "trusted proxies" that can be stripped from the right-hand-side of X-Forwarded-For

Methods

Instance

Visibility Signature
public GET ()
public POST ()
public accepts ()
public body ()
public cache_format ()
public content_length ()
public content_type ()
public delete? ()
public domain (tld_length = 1)
public etag_matches? (etag)
public form_data? ()
public format ()
public format= (extension)
public fresh? (response)
public get? ()
public head? ()
public headers ()
public host ()
public host_with_port ()
public if_modified_since ()
public if_none_match ()
public key? (key)
public method ()
public not_modified? (modified_at)
public parameters ()
public params ()
public path ()
public path_parameters ()
public port ()
public port_string ()
public post? ()
public protocol ()
public put? ()
public query_parameters ()
public query_string ()
public raw_host_with_port ()
public raw_post ()
public remote_ip ()
public request_method ()
public request_parameters ()
public request_uri ()
public reset_session ()
public server_port ()
public server_software ()
public session ()
public session_options ()
public session_options= (options)
public ssl? ()
public standard_port ()
public subdomains (tld_length = 1)
public symbolized_path_parameters ()
public template_format ()
public url ()
public xhr? ()
public xml_http_request? ()

Instance Method Detail

GET()

Override Rack‘s GET method to support indifferent access

POST()

Override Rack‘s POST method to support indifferent access

accepts()

Returns the accepted MIME type for the request.

body()

The request body is an IO input stream. If the RAW_POST_DATA environment variable is already set, wrap it in a StringIO.

cache_format()

content_length()

Returns the content length of the request as an integer.

content_type()

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

For backward compatibility, the post \format is extracted from the X-Post-Data-Format HTTP header if present.

delete?()

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

domain(tld_length = 1)

Returns the \domain part of a \host, such as "rubyonrails.org" in "www.rubyonrails.org". You can specify a different tld_length, such as 2 to catch rubyonrails.co.uk in "www.rubyonrails.co.uk".

etag_matches?(etag)

form_data?()

format()

Returns the Mime type for the \format used in the request.

  GET /posts/5.xml   | request.format => Mime::XML
  GET /posts/5.xhtml | request.format => Mime::HTML
  GET /posts/5       | request.format => Mime::HTML or MIME::JS, or request.accepts.first depending on the value of <tt>ActionController::Base.use_accept_header</tt>

format=(extension)

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

  class ApplicationController < ActionController::Base
    before_filter :adjust_format_for_iphone

    private
      def adjust_format_for_iphone
        request.format = :iphone if request.env["HTTP_USER_AGENT"][/iPhone/]
      end
  end

fresh?(response)

Check response freshness (Last-Modified and ETag) against request If-Modified-Since and If-None-Match conditions. If both headers are supplied, both must match, or the request is not considered fresh.

get?()

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

head?()

Is this a HEAD request? Since request.method sees HEAD as :get, this \method checks the actual HTTP \method directly.

headers()

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

  request.headers["Content-Type"] # => "text/plain"

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

if_modified_since()

if_none_match()

key?(key)

method()

Returns the HTTP request \method used for action processing as a lowercase symbol, such as :post. (Unlike request_method, this method returns :get for a HEAD request because the two are functionally equivalent from the application‘s perspective.)

not_modified?(modified_at)

parameters()

Returns both GET and POST \parameters in a single hash.

params()

Alias for parameters

path()

Returns the interpreted \path to requested resource after all the installation directory of this application was taken into account.

path_parameters()

Returns a hash with the \parameters used to form the \path of the request. Returned hash keys are strings:

  {'action' => 'my_action', 'controller' => 'my_controller'}

See symbolized_path_parameters for symbolized keys.

port()

Returns the port number of this request as an integer.

port_string()

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

post?()

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

protocol()

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

put?()

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

query_parameters()

Alias for GET

query_string()

Returns the query string, accounting for server idiosyncrasies.

raw_host_with_port()

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

raw_post()

Read the request \body. This is useful for web services that need to work with raw requests directly.

remote_ip()

Determines originating IP address. REMOTE_ADDR is the standard but will fail if the user is behind a proxy. HTTP_CLIENT_IP and/or HTTP_X_FORWARDED_FOR are set by proxies so check for these if REMOTE_ADDR is a proxy. HTTP_X_FORWARDED_FOR may be a comma- delimited list in the case of multiple chained proxies; the last address which is not trusted is the originating IP.

request_method()

Returns the true HTTP request \method as a lowercase symbol, such as :get. If the request \method is not listed in the HTTP_METHODS constant above, an UnknownHttpMethod exception is raised.

request_parameters()

Alias for POST

request_uri()

Returns the request URI, accounting for server idiosyncrasies. WEBrick includes the full URL. IIS leaves REQUEST_URI blank.

reset_session()

server_port()

server_software()

Returns the lowercase name of the HTTP server software.

session()

session_options()

session_options=(options)

ssl?()

Is this an SSL request?

standard_port()

Returns the standard \port number for this request‘s protocol.

subdomains(tld_length = 1)

Returns all the \subdomains as an array, so ["dev", "www"] would be returned for "dev.www.rubyonrails.org". You can specify a different tld_length, such as 2 to catch ["www"] instead of ["www", "rubyonrails"] in "www.rubyonrails.co.uk".

symbolized_path_parameters()

The same as path_parameters with explicitly symbolized keys.

template_format()

Returns a symbolized version of the :format parameter of the request. If no \format is given it returns :jsfor Ajax requests and :html otherwise.

url()

Returns the complete URL used for this request.

xhr?()

Alias for xml_http_request?

xml_http_request?()

Returns true if the request‘s "X-Requested-With" header contains "XMLHttpRequest". (The Prototype Javascript library sends this header with every Ajax request.)