CgiRequest and TestRequest provide concrete implementations.

Methods
Constants
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
MULTIPART_BOUNDARY = %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n
EOL = "\015\012"
Attributes
[R] env The hash of environment variables for this request, such as { ‘RAILS_ENV’ => ‘production’ }.
Public Class methods
relative_url_root=(relative_url_root)
    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 12
12:     def self.relative_url_root=(relative_url_root)
13:       ActiveSupport::Deprecation.warn(
14:         "ActionController::AbstractRequest.relative_url_root= has been renamed." +
15:         "You can now set it with config.action_controller.relative_url_root=", caller)
16:       ActionController::Base.relative_url_root=relative_url_root
17:     end
Public Instance methods
accepts()

Returns the accepted MIME type for the request.

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 93
 93:     def accepts
 94:       header = @env['HTTP_ACCEPT'].to_s.strip
 95: 
 96:       if header.empty?
 97:         [content_type, Mime::ALL].compact
 98:       else
 99:         Mime::Type.parse(header)
100:       end
101:     end
body()

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

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 418
418:     def body
419:       if raw_post = env['RAW_POST_DATA']
420:         raw_post.force_encoding(Encoding::BINARY) if raw_post.respond_to?(:force_encoding)
421:         StringIO.new(raw_post)
422:       else
423:         body_stream
424:       end
425:     end
cache_format()
     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 189
189:     def cache_format
190:       parameters[:format]
191:     end
content_length()

Returns the content length of the request as an integer.

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 78
78:     def content_length
79:       @env['CONTENT_LENGTH'].to_i
80:     end
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.

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 87
87:     def content_type
88:       Mime::Type.lookup(content_type_without_parameters)
89:     end
delete?()

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

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 59
59:     def delete?
60:       request_method == :delete
61:     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 318
318:     def domain(tld_length = 1)
319:       return nil unless named_host?(host)
320: 
321:       host.split('.').last(1 + tld_length).join('.')
322:     end
etag_matches?(etag)
     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 119
119:     def etag_matches?(etag)
120:       if_none_match && if_none_match == etag
121:     end
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>
     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 144
144:     def format
145:       @format ||=
146:         if parameters[:format]
147:           Mime::Type.lookup_by_extension(parameters[:format])
148:         elsif ActionController::Base.use_accept_header
149:           accepts.first
150:         elsif xhr?
151:           Mime::Type.lookup_by_extension("js")
152:         else
153:           Mime::Type.lookup_by_extension("html")
154:         end
155:     end
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
     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 169
169:     def format=(extension)
170:       parameters[:format] = extension.to_s
171:       @format = Mime::Type.lookup_by_extension(parameters[:format])
172:     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.

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 126
126:     def fresh?(response)
127:       case
128:       when if_modified_since && if_none_match 
129:         not_modified?(response.last_modified) && etag_matches?(response.etag) 
130:       when if_modified_since 
131:         not_modified?(response.last_modified) 
132:       when if_none_match 
133:         etag_matches?(response.etag) 
134:       else 
135:         false 
136:       end 
137:     end
get?()

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

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

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

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 65
65:     def head?
66:       request_method == :head
67:     end
headers()

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

  request.headers["Content-Type"] # => "text/plain"
    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 72
72:     def headers
73:       ActionController::Http::Headers.new(@env)
74:     end
host()

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

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 280
280:     def host
281:       raw_host_with_port.sub(/:\d+$/, '')
282:     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 287
287:     def host_with_port
288:       "#{host}#{port_string}"
289:     end
if_modified_since()
     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 104
104:     def if_modified_since
105:       if since = env['HTTP_IF_MODIFIED_SINCE']
106:         Time.rfc2822(since) rescue nil
107:       end
108:     end
if_none_match()
     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 111
111:     def if_none_match
112:       env['HTTP_IF_NONE_MATCH']
113:     end
method()

The HTTP request \method as a lowercase symbol, such as :get. Note, HEAD is returned as :get since the two are functionally equivalent from the application‘s perspective.

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 39
39:     def method
40:       request_method == :head ? :get : request_method
41:     end
not_modified?(modified_at)
     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 115
115:     def not_modified?(modified_at)
116:       if_modified_since && modified_at && if_modified_since >= modified_at
117:     end
parameters()

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

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 392
392:     def parameters
393:       @parameters ||= request_parameters.merge(query_parameters).update(path_parameters).with_indifferent_access
394:     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 372
372:     def path
373:       path = (uri = request_uri) ? uri.split('?').first.to_s : ''
374: 
375:       # Cut off the path to the installation directory if given
376:       path.sub!(%r/^#{ActionController::Base.relative_url_root}/, '')
377:       path || ''
378:     end
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.

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 412
412:     def path_parameters
413:       @path_parameters ||= {}
414:     end
port()

Returns the port number of this request as an integer.

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 293
293:     def port
294:       if raw_host_with_port =~ /:(\d+)$/
295:         $1.to_i
296:       else
297:         standard_port
298:       end
299:     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 312
312:     def port_string
313:       port == standard_port ? '' : ":#{port}"
314:     end
post?()

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

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 49
49:     def post?
50:       request_method == :post
51:     end
protocol()

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

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

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

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 54
54:     def put?
55:       request_method == :put
56:     end
query_parameters()
     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 437
437:     def query_parameters
438:       @query_parameters ||= self.class.parse_query_parameters(query_string)
439:     end
query_string()

Returns the query string, accounting for server idiosyncrasies.

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 335
335:     def query_string
336:       if uri = @env['REQUEST_URI']
337:         uri.split('?', 2)[1] || ''
338:       else
339:         @env['QUERY_STRING'] || ''
340:       end
341:     end
raw_host_with_port()

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

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 271
271:     def raw_host_with_port
272:       if forwarded = env["HTTP_X_FORWARDED_HOST"]
273:         forwarded.split(/,\s?/).last
274:       else
275:         env['HTTP_HOST'] || env['SERVER_NAME'] || "#{env['SERVER_ADDR']}:#{env['SERVER_PORT']}"
276:       end
277:     end
raw_post()

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

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 383
383:     def raw_post
384:       unless env.include? 'RAW_POST_DATA'
385:         env['RAW_POST_DATA'] = body.read(content_length)
386:         body.rewind if body.respond_to?(:rewind)
387:       end
388:       env['RAW_POST_DATA']
389:     end
referer()

Alias for referrer

referrer()
This method is also aliased as referer
     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 431
431:     def referrer
432:       @env['HTTP_REFERER']
433:     end
remote_addr()
     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 427
427:     def remote_addr
428:       @env['REMOTE_ADDR']
429:     end
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.

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 211
211:     def remote_ip
212:       remote_addr_list = @env['REMOTE_ADDR'] && @env['REMOTE_ADDR'].split(',').collect(&:strip)
213: 
214:       unless remote_addr_list.blank?
215:         not_trusted_addrs = remote_addr_list.reject {|addr| addr =~ TRUSTED_PROXIES}
216:         return not_trusted_addrs.first unless not_trusted_addrs.empty?
217:       end
218:       remote_ips = @env['HTTP_X_FORWARDED_FOR'] && @env['HTTP_X_FORWARDED_FOR'].split(',')
219: 
220:       if @env.include? 'HTTP_CLIENT_IP'
221:         if remote_ips && !remote_ips.include?(@env['HTTP_CLIENT_IP'])
222:           # We don't know which came from the proxy, and which from the user
223:           raise ActionControllerError.new("IP spoofing attack?!\nHTTP_CLIENT_IP=\#{@env['HTTP_CLIENT_IP'].inspect}\nHTTP_X_FORWARDED_FOR=\#{@env['HTTP_X_FORWARDED_FOR'].inspect}\n")
224:         end
225: 
226:         return @env['HTTP_CLIENT_IP']
227:       end
228: 
229:       if remote_ips
230:         while remote_ips.size > 1 && TRUSTED_PROXIES =~ remote_ips.last.strip
231:           remote_ips.pop
232:         end
233: 
234:         return remote_ips.last.strip
235:       end
236: 
237:       @env['REMOTE_ADDR']
238:     end
request_method()

The true HTTP request \method as a lowercase symbol, such as :get. UnknownHttpMethod is raised for invalid methods not listed in ACCEPTED_HTTP_METHODS.

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 28
28:     def request_method
29:       method = @env['REQUEST_METHOD']
30:       method = parameters[:_method] if method == 'POST' && !parameters[:_method].blank?
31: 
32:       HTTP_METHOD_LOOKUP[method] || raise(UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence}")
33:     end
request_parameters()
     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 441
441:     def request_parameters
442:       @request_parameters ||= parse_formatted_request_parameters
443:     end
request_uri()

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

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 346
346:     def request_uri
347:       if uri = @env['REQUEST_URI']
348:         # Remove domain, which webrick puts into the request_uri.
349:         (%r{^\w+\://[^/]+(/.*|$)$} =~ uri) ? $1 : uri
350:       else
351:         # Construct IIS missing REQUEST_URI from SCRIPT_NAME and PATH_INFO.
352:         uri = @env['PATH_INFO'].to_s
353: 
354:         if script_filename = @env['SCRIPT_NAME'].to_s.match(%r{[^/]+$})
355:           uri = uri.sub(/#{script_filename}\//, '')
356:         end
357: 
358:         env_qs = @env['QUERY_STRING'].to_s
359:         uri += "?#{env_qs}" unless env_qs.empty?
360: 
361:         if uri.blank?
362:           @env.delete('REQUEST_URI')
363:         else
364:           @env['REQUEST_URI'] = uri
365:         end
366:       end
367:     end
server_software()

Returns the lowercase name of the HTTP server software.

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

Is this an SSL request?

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

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

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 303
303:     def standard_port
304:       case protocol
305:         when 'https://' then 443
306:         else 80
307:       end
308:     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 328
328:     def subdomains(tld_length = 1)
329:       return [] unless named_host?(host)
330:       parts = host.split('.')
331:       parts[0..-(tld_length+2)]
332:     end
symbolized_path_parameters()

The same as path_parameters with explicitly symbolized keys.

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 402
402:     def symbolized_path_parameters
403:       @symbolized_path_parameters ||= path_parameters.symbolize_keys
404:     end
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.

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 177
177:     def template_format
178:       parameter_format = parameters[:format]
179: 
180:       if parameter_format
181:         parameter_format
182:       elsif xhr?
183:         :js
184:       else
185:         :html
186:       end
187:     end
url()

Returns the complete URL used for this request.

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 254
254:     def url
255:       protocol + host_with_port + request_uri
256:     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 196
196:     def xml_http_request?
197:       !(@env['HTTP_X_REQUESTED_WITH'] !~ /XMLHttpRequest/i)
198:     end
Protected Instance methods
content_type_with_parameters()

The raw content type string. Use when you need parameters such as charset or boundary which aren‘t included in the content_type MIME type. Overridden by the X-POST_DATA_FORMAT header for backward compatibility.

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 470
470:       def content_type_with_parameters
471:         content_type_from_legacy_post_data_format_header ||
472:           env['CONTENT_TYPE'].to_s
473:       end
content_type_without_parameters()

The raw content type string with its parameters stripped off.

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 476
476:       def content_type_without_parameters
477:         self.class.extract_content_type_without_parameters(content_type_with_parameters)
478:       end