These methods are available in both the production and test Request objects.

Methods
Public Instance methods
delete?()

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

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 32
32:     def delete?
33:       method == :delete
34:     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 vendor/rails/actionpack/lib/action_controller/request.rb, line 111
111:     def domain(tld_length = 1)
112:       return nil if !/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/.match(host).nil? or host.nil?
113: 
114:       host.split('.').last(1 + tld_length).join('.')
115:     end
env()

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

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 230
230:     def env
231:     end
formatted_post?()

Is this a POST request formatted as XML or YAML?

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 67
67:     def formatted_post?
68:       post? && (post_format == :xml || post_format == :yaml)
69:     end
get?()

Is this a GET request? Equivalent to request.method == :get

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

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

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 37
37:     def head?
38:       method == :head
39:     end
host()

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

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 234
234:     def host
235:     end
host_with_port()

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

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 197
197:     def host_with_port
198:       host + port_string
199:     end
method()

Returns the HTTP request method as a lowercase symbol (:get, for example)

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 12
12:     def method
13:       env['REQUEST_METHOD'].downcase.to_sym
14:     end
parameters()

Returns both GET and POST parameters in a single hash.

   # File vendor/rails/actionpack/lib/action_controller/request.rb, line 7
7:     def parameters
8:       @parameters ||= request_parameters.merge(query_parameters).merge(path_parameters).with_indifferent_access
9:     end
path()

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

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 160
160:     def path
161:       path = (uri = request_uri) ? uri.split('?').first : ''
162: 
163:       # Cut off the path to the installation directory if given
164:       root = relative_url_root
165:       path[0, root.length] = '' if root
166:       path || ''
167:     end
path_parameters()
     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 210
210:     def path_parameters
211:       @path_parameters ||= {}
212:     end
path_parameters=(parameters)
     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 201
201:     def path_parameters=(parameters)
202:       @path_parameters = parameters
203:       @symbolized_path_parameters = @parameters = nil
204:     end
port()

Returns the port number of this request as an integer.

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 177
177:     def port
178:       @port_as_int ||= env['SERVER_PORT'].to_i
179:     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 vendor/rails/actionpack/lib/action_controller/request.rb, line 191
191:     def port_string
192:       (port == standard_port) ? '' : ":#{port}"
193:     end
post?()

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

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

Determine whether the body of a POST request is URL-encoded (default), XML, or YAML by checking the Content-Type HTTP header:

  Content-Type        Post Format
  application/xml     :xml
  text/xml            :xml
  application/x-yaml  :yaml
  text/x-yaml         :yaml
  *                   :url_encoded

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

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 53
53:     def post_format
54:       @post_format ||=
55:            if env['HTTP_X_POST_DATA_FORMAT']
56:              env['HTTP_X_POST_DATA_FORMAT'].downcase.to_sym
57:            else
58:              case env['CONTENT_TYPE'].to_s.downcase
59:              when 'application/xml', 'text/xml'        then :xml
60:              when 'application/x-yaml', 'text/x-yaml'  then :yaml
61:              else :url_encoded
62:              end
63:            end
64:     end
protocol()

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

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

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

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 27
27:     def put?
28:       method == :put
29:     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 vendor/rails/actionpack/lib/action_controller/request.rb, line 129
129:     def raw_post
130:       env['RAW_POST_DATA']
131:     end
relative_url_root()

Returns the path minus the web server relative installation directory. This method returns nil unless the web server is apache.

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 171
171:     def relative_url_root
172:       @@relative_url_root ||= server_software == 'apache' ? env["SCRIPT_NAME"].to_s.sub(/\/dispatch\.(fcgi|rb|cgi)$/, '') : ''
173:       
174:     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 vendor/rails/actionpack/lib/action_controller/request.rb, line 95
 95:     def remote_ip
 96:       return env['HTTP_CLIENT_IP'] if env.include? 'HTTP_CLIENT_IP'
 97: 
 98:       if env.include? 'HTTP_X_FORWARDED_FOR' then
 99:         remote_ips = env['HTTP_X_FORWARDED_FOR'].split(',').reject do |ip|
100:             ip =~ /^unknown$|^(10|172\.(1[6-9]|2[0-9]|30|31)|192\.168)\./i
101:         end
102: 
103:         return remote_ips.first.strip unless remote_ips.empty?
104:       end
105: 
106:       env['REMOTE_ADDR']
107:     end
request_uri()

Returns the request URI correctly, taking into account the idiosyncracies of the various servers.

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 135
135:     def request_uri
136:       if uri = env['REQUEST_URI']
137:         (%r{^\w+\://[^/]+(/.*|$)$} =~ uri) ? $1 : uri # Remove domain, which webrick puts into the request_uri.
138:       else  # REQUEST_URI is blank under IIS - get this from PATH_INFO and SCRIPT_NAME
139:         script_filename = env['SCRIPT_NAME'].to_s.match(%r{[^/]+$})
140:         uri = env['PATH_INFO']
141:         uri = uri.sub(/#{script_filename}\//, '') unless script_filename.nil?
142:         unless (env_qs = env['QUERY_STRING']).nil? || env_qs.empty?
143:           uri << '?' << env_qs
144:         end
145:         uri
146:       end
147:     end
server_software()

Returns the lowercase name of the HTTP server software.

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

Is this an SSL request?

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 155
155:     def ssl?
156:       env['HTTPS'] == 'on'
157:     end
standard_port()

Returns the standard port number for this request’s protocol

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 182
182:     def standard_port
183:       case protocol
184:         when 'https://' then 443
185:         else 80
186:       end
187:     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 vendor/rails/actionpack/lib/action_controller/request.rb, line 120
120:     def subdomains(tld_length = 1)
121:       return [] unless host
122:       parts = host.split('.')
123:       parts[0..-(tld_length+2)]
124:     end
symbolized_path_parameters()
     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 206
206:     def symbolized_path_parameters
207:       @symbolized_path_parameters ||= path_parameters.symbolize_keys
208:     end
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.)

This method is also aliased as xhr?
    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 84
84:     def xml_http_request?
85:       not /XMLHttpRequest/i.match(env['HTTP_X_REQUESTED_WITH']).nil?
86:     end
xml_post?()

Is this a POST request formatted as XML?

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 72
72:     def xml_post?
73:       post? && post_format == :xml
74:     end
yaml_post?()

Is this a POST request formatted as YAML?

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 77
77:     def yaml_post?
78:       post? && post_format == :yaml
79:     end