Subclassing AbstractRequest makes these methods available to the request objects used in production and testing, CgiRequest and TestRequest

Methods
A
C
D
F
G
H
M
P
R
S
X
Y
Attributes
[R] env

Returns the hash of environment variables for this request, such as { ‘RAILS_ENV’ => ‘production’ }.

Instance Public methods
accepts()

Returns the accepted MIME type for the request

# File rails/actionpack/lib/action_controller/request.rb, line 77
def accepts
  @accepts ||=
    if @env['HTTP_ACCEPT'].to_s.strip.empty?
      [ content_type, Mime::ALL ]
    else
      Mime::Type.parse(@env['HTTP_ACCEPT'])
    end
end
content_type()

Determine whether the body of a HTTP call is URL-encoded (default) or matches one of the registered param_parsers.

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

# File rails/actionpack/lib/action_controller/request.rb, line 58
def content_type
  @content_type ||=
    begin
      content_type = @env['CONTENT_TYPE'].to_s.downcase
      
      if x_post_format = @env['HTTP_X_POST_DATA_FORMAT']
        case x_post_format.to_s.downcase
        when 'yaml'
          content_type = 'application/x-yaml'
        when 'xml'
          content_type = 'application/xml'
        end
      end
      
      Mime::Type.lookup(content_type)
    end
end
delete?()

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

# File rails/actionpack/lib/action_controller/request.rb, line 43
def delete?
  method == :delete
end
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”.

# File rails/actionpack/lib/action_controller/request.rb, line 116
def domain(tld_length = 1)
  return nil if !%r\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/.match(host).nil? or host.nil?

  host.split('.').last(1 + tld_length).join('.')
end
formatted_post?()

Is this a POST request formatted as XML or YAML?

# File rails/actionpack/lib/action_controller/deprecated_request_methods.rb, line 20
def formatted_post?
  post? && (post_format == :yaml || post_format == :xml)
end
get?()

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

# File rails/actionpack/lib/action_controller/request.rb, line 28
def get?
  method == :get
end
head?()

Is this a HEAD request? HEAD is mapped as :get for request.method, so here we ask the REQUEST_METHOD header directly. Thus, for head, both get? and head? will return true.

# File rails/actionpack/lib/action_controller/request.rb, line 49
def head?
  @env['REQUEST_METHOD'].downcase.to_sym == :head
end
host()

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

# File rails/actionpack/lib/action_controller/request.rb, line 249
def host
end
host_with_port()

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

# File rails/actionpack/lib/action_controller/request.rb, line 211
def host_with_port
  host + port_string
end
method()

Returns the HTTP request method as a lowercase symbol (:get, for example). Note, HEAD is returned as :get since the two are supposedly to be functionaly equivilent for all purposes except that HEAD won’t return a response body (which Rails also takes care of elsewhere).

# File rails/actionpack/lib/action_controller/request.rb, line 19
def method
  @request_method ||= (!parameters[:_method].blank? && @env['REQUEST_METHOD'] == 'POST') ?
    parameters[:_method].to_s.downcase.to_sym :
    @env['REQUEST_METHOD'].downcase.to_sym
  
  @request_method == :head ? :get : @request_method
end
parameters()

Returns both GET and POST parameters in a single hash.

# File rails/actionpack/lib/action_controller/request.rb, line 12
def parameters
  @parameters ||= request_parameters.update(query_parameters).update(path_parameters).with_indifferent_access
end
path()

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

# File rails/actionpack/lib/action_controller/request.rb, line 167
def path
  path = (uri = request_uri) ? uri.split('?').first : ''

  # Cut off the path to the installation directory if given
  path.sub!(%r^#{relative_url_root}/, '')
  path || ''      
end
path_parameters()

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

Example:

{:action => 'my_action', :controller => 'my_controller'}
# File rails/actionpack/lib/action_controller/request.rb, line 230
def path_parameters
  @path_parameters ||= {}
end
port()

Returns the port number of this request as an integer.

# File rails/actionpack/lib/action_controller/request.rb, line 191
def port
  @port_as_int ||= @env['SERVER_PORT'].to_i
end
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.

# File rails/actionpack/lib/action_controller/request.rb, line 205
def port_string
  (port == standard_port) ? '' : ":#{port}"
end
post?()

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

# File rails/actionpack/lib/action_controller/request.rb, line 33
def post?
  method == :post
end
post_format()

Determine whether the body of a HTTP call is URL-encoded (default) or matches one of the registered param_parsers.

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

# File rails/actionpack/lib/action_controller/deprecated_request_methods.rb, line 8
def post_format
  case content_type.to_s
  when 'application/xml'
    :xml
  when 'application/x-yaml'
    :yaml
  else
    :url_encoded
  end
end
protocol()

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

# File rails/actionpack/lib/action_controller/request.rb, line 157
def protocol
  ssl? ? 'https://' : 'http://'
end
put?()

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

# File rails/actionpack/lib/action_controller/request.rb, line 38
def put?
  method == :put
end
raw_post()

Receive the raw post data. This is useful for services such as REST, XMLRPC and SOAP which communicate over HTTP POST but don’t use the traditional parameter format.

# File rails/actionpack/lib/action_controller/request.rb, line 134
def raw_post
  @env['RAW_POST_DATA']
end
relative_url_root()

Returns the path minus the web server relative installation directory. This can be set with the environment variable RAILS_RELATIVE_URL_ROOT. It can be automatically extracted for Apache setups. If the server is not Apache, this method returns an empty string.

# File rails/actionpack/lib/action_controller/request.rb, line 179
def relative_url_root
  @@relative_url_root ||= case
    when @env["RAILS_RELATIVE_URL_ROOT"]
      @env["RAILS_RELATIVE_URL_ROOT"]
    when server_software == 'apache'
      @env["SCRIPT_NAME"].to_s.sub(%r\/dispatch\.(fcgi|rb|cgi)$/, '')
    else
      ''
  end
end
remote_ip()

Determine 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 before falling back to REMOTE_ADDR. HTTP_X_FORWARDED_FOR may be a comma- delimited list in the case of multiple chained proxies; the first is the originating IP.

# File rails/actionpack/lib/action_controller/request.rb, line 100
def remote_ip
  return @env['HTTP_CLIENT_IP'] if @env.include? 'HTTP_CLIENT_IP'

  if @env.include? 'HTTP_X_FORWARDED_FOR' then
    remote_ips = @env['HTTP_X_FORWARDED_FOR'].split(',').reject do |ip|
        ip =~ %r^unknown$|^(10|172\.(1[6-9]|2[0-9]|30|31)|192\.168)\./
    end

    return remote_ips.first.strip unless remote_ips.empty?
  end

  @env['REMOTE_ADDR']
end
request_uri()

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

# File rails/actionpack/lib/action_controller/request.rb, line 140
def request_uri
  if uri = @env['REQUEST_URI']
    # Remove domain, which webrick puts into the request_uri.
    (%r{^\w+\://[^/]+(/.*|$)$} =~ uri) ? $1 : uri
  else
    # Construct IIS missing REQUEST_URI from SCRIPT_NAME and PATH_INFO.
    script_filename = @env['SCRIPT_NAME'].to_s.match(%r{[^/]+$})
    uri = @env['PATH_INFO']
    uri = uri.sub(%r#{script_filename}\//, '') unless script_filename.nil?
    unless (env_qs = @env['QUERY_STRING']).nil? || env_qs.empty?
      uri << '?' << env_qs
    end
    @env['REQUEST_URI'] = uri
  end
end
server_software()

Returns the lowercase name of the HTTP server software.

# File rails/actionpack/lib/action_controller/request.rb, line 235
def server_software
  (@env['SERVER_SOFTWARE'] && %r^([a-zA-Z]+)/ =~ @env['SERVER_SOFTWARE']) ? $1.downcase : nil
end
ssl?()

Is this an SSL request?

# File rails/actionpack/lib/action_controller/request.rb, line 162
def ssl?
  @env['HTTPS'] == 'on' || @env['HTTP_X_FORWARDED_PROTO'] == 'https'
end
standard_port()

Returns the standard port number for this request’s protocol

# File rails/actionpack/lib/action_controller/request.rb, line 196
def standard_port
  case protocol
    when 'https://' then 443
    else 80
  end
end
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”.

# File rails/actionpack/lib/action_controller/request.rb, line 125
def subdomains(tld_length = 1)
  return [] unless host
  parts = host.split('.')
  parts[0..-(tld_length+2)]
end
symbolized_path_parameters()

The same as path_parameters with explicitly symbolized keys

# File rails/actionpack/lib/action_controller/request.rb, line 221
def symbolized_path_parameters 
  @symbolized_path_parameters ||= path_parameters.symbolize_keys
end
xhr?()
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.)

Also aliased as: xhr?
# File rails/actionpack/lib/action_controller/request.rb, line 89
def xml_http_request?
  not %rXMLHttpRequest/.match(@env['HTTP_X_REQUESTED_WITH']).nil?
end
xml_post?()

Is this a POST request formatted as XML?

# File rails/actionpack/lib/action_controller/deprecated_request_methods.rb, line 25
def xml_post?
  post? && post_format == :xml
end
yaml_post?()

Is this a POST request formatted as YAML?

# File rails/actionpack/lib/action_controller/deprecated_request_methods.rb, line 30
def yaml_post?
  post? && post_format == :yaml
end