Class ActionController::AbstractRequest
In: vendor/rails/actionpack/lib/action_controller/request.rb
Parent: Object

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

Methods

Public Instance methods

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 219
219:     def cookies
220:     end

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

[Source]

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 32
32:     def delete?
33:       method == :delete
34:     end

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

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 110
110:     def domain(tld_length = 1)
111:       host.split('.').last(1 + tld_length).join('.')
112:     end

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 213
213:     def env
214:     end

Is this a POST request formatted as XML or YAML?

[Source]

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 66
66:     def formatted_post?
67:       [ :xml, :yaml ].include?(post_format) && post?
68:     end

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

[Source]

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

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

[Source]

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

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 216
216:     def host
217:     end

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

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 182
182:     def host_with_port
183:       env['HTTP_HOST'] || host + port_string
184:     end

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

[Source]

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

Returns both GET and POST parameters in a single hash.

[Source]

   # 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

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

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 152
152:     def path
153:       path = (uri = request_uri) ? uri.split('?').first : ''
154: 
155:       # Cut off the path to the installation directory if given
156:       if root = relative_url_root
157:         path[root.length..-1]
158:       else
159:         path
160:       end
161:     end

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 195
195:     def path_parameters
196:       @path_parameters ||= {}
197:     end

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 186
186:     def path_parameters=(parameters)
187:       @path_parameters = parameters
188:       @symbolized_path_parameters = @parameters = nil
189:     end

Returns the port number of this request as an integer.

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 170
170:     def port
171:       env['SERVER_PORT'].to_i
172:     end

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

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 176
176:     def port_string
177:       (protocol == 'http://' && port == 80) || (protocol == 'https://' && port == 443) ? '' : ":#{port}"
178:     end

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

[Source]

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

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.

[Source]

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

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

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 142
142:     def protocol
143:       env["HTTPS"] == "on" ? 'https://' : 'http://'
144:     end

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

[Source]

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 27
27:     def put?
28:       method == :put
29:     end

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 207
207:     def query_parameters
208:     end

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.

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 125
125:     def raw_post
126:       env['RAW_POST_DATA']
127:     end

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

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 165
165:     def relative_url_root
166:       @@relative_url_root ||= File.dirname(env["SCRIPT_NAME"].to_s).gsub(/(^\.$|^\/$)/, '') if server_software == 'apache'
167:     end

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.

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 94
 94:     def remote_ip
 95:       return env['HTTP_CLIENT_IP'] if env.include? 'HTTP_CLIENT_IP'
 96: 
 97:       if env.include? 'HTTP_X_FORWARDED_FOR' then
 98:         remote_ips = env['HTTP_X_FORWARDED_FOR'].split(',').reject do |ip|
 99:             ip =~ /^unknown$|^(10|172\.(1[6-9]|2[0-9]|30|31)|192\.168)\./i
100:         end
101: 
102:         return remote_ips.first.strip unless remote_ips.empty?
103:       end
104: 
105:       return env['REMOTE_ADDR']
106:     end

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 210
210:     def request_parameters
211:     end

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 129
129:     def request_uri
130:       unless env['REQUEST_URI'].nil?
131:         (%r{^\w+\://[^/]+(/.*|$)$} =~ env['REQUEST_URI']) ? $1 : env['REQUEST_URI'] # Remove domain, which webrick puts into the request_uri.
132:       else  # REQUEST_URI is blank under IIS - get this from PATH_INFO and SCRIPT_NAME
133:         script_filename = env["SCRIPT_NAME"].to_s.match(%r{[^/]+$})
134:         request_uri = env["PATH_INFO"]
135:         request_uri.sub!(/#{script_filename}\//, '') unless script_filename.nil?
136:         request_uri += '?' + env["QUERY_STRING"] unless env["QUERY_STRING"].nil? || env["QUERY_STRING"].empty?
137:         return request_uri
138:       end
139:     end

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 225
225:     def reset_session
226:     end

Returns the lowercase name of the HTTP server software.

[Source]

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

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 222
222:     def session
223:     end

Is this an SSL request?

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 147
147:     def ssl?
148:       protocol == 'https://'
149:     end

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

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 117
117:     def subdomains(tld_length = 1)
118:       parts = host.split('.')
119:       parts - parts.last(1 + tld_length)
120:     end

[Source]

     # File vendor/rails/actionpack/lib/action_controller/request.rb, line 191
191:     def symbolized_path_parameters
192:       @symbolized_path_parameters ||= path_parameters.symbolize_keys
193:     end
xhr?()

Alias for 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.)

[Source]

    # File vendor/rails/actionpack/lib/action_controller/request.rb, line 83
83:     def xml_http_request?
84:       not /XMLHttpRequest/i.match(env['HTTP_X_REQUESTED_WITH']).nil?
85:     end

Is this a POST request formatted as XML?

[Source]

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

Is this a POST request formatted as YAML?

[Source]

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

[Validate]