Parent

Class Index [+]

Quicksearch

ActionDispatch::Request

Constants

LOCALHOST
RFC2616

List of HTTP request methods from the following RFCs: Hypertext Transfer Protocol — HTTP/1.1 (www.ietf.org/rfc/rfc2616.txt) HTTP Extensions for Distributed Authoring — WEBDAV (www.ietf.org/rfc/rfc2518.txt) Versioning Extensions to WebDAV (www.ietf.org/rfc/rfc3253.txt) Ordered Collections Protocol (WebDAV) (www.ietf.org/rfc/rfc3648.txt) Web Distributed Authoring and Versioning (WebDAV) Access Control Protocol (www.ietf.org/rfc/rfc3744.txt) Web Distributed Authoring and Versioning (WebDAV) SEARCH (www.ietf.org/rfc/rfc5323.txt) PATCH Method for HTTP (www.ietf.org/rfc/rfc5789.txt)

RFC2518
RFC3253
RFC3648
RFC3744
RFC5323
RFC5789
HTTP_METHODS
HTTP_METHOD_LOOKUP
TRUSTED_PROXIES

Which IP addresses are “trusted proxies” that can be stripped from the right-hand-side of X-Forwarded-For

Public Class Methods

new(env) click to toggle source
    # File lib/action_dispatch/http/request.rb, line 36
36:     def self.new(env)
37:       if request = env["action_dispatch.request"] && request.instance_of?(self)
38:         return request
39:       end
40: 
41:       super
42:     end

Public Instance Methods

GET() click to toggle source

Override Rack’s GET method to support indifferent access

     # File lib/action_dispatch/http/request.rb, line 233
233:     def GET
234:       @env["action_dispatch.request.query_parameters"] ||= normalize_parameters(super)
235:     end
Also aliased as: query_parameters
POST() click to toggle source

Override Rack’s POST method to support indifferent access

     # File lib/action_dispatch/http/request.rb, line 239
239:     def POST
240:       @env["action_dispatch.request.request_parameters"] ||= normalize_parameters(super)
241:     end
Also aliased as: request_parameters
authorization() click to toggle source

Returns the authorization header regardless of whether it was specified directly or through one of the proxy alternatives.

     # File lib/action_dispatch/http/request.rb, line 247
247:     def authorization
248:       @env['HTTP_AUTHORIZATION']   ||
249:       @env['X-HTTP_AUTHORIZATION'] ||
250:       @env['X_HTTP_AUTHORIZATION'] ||
251:       @env['REDIRECT_X_HTTP_AUTHORIZATION']
252:     end
body() click to toggle source

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

     # File lib/action_dispatch/http/request.rb, line 199
199:     def body
200:       if raw_post = @env['RAW_POST_DATA']
201:         raw_post.force_encoding(Encoding::BINARY) if raw_post.respond_to?(:force_encoding)
202:         StringIO.new(raw_post)
203:       else
204:         @env['rack.input']
205:       end
206:     end
content_length() click to toggle source

Returns the content length of the request as an integer.

     # File lib/action_dispatch/http/request.rb, line 152
152:     def content_length
153:       super.to_i
154:     end
delete?() click to toggle source

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

     # File lib/action_dispatch/http/request.rb, line 122
122:     def delete?
123:       HTTP_METHOD_LOOKUP[request_method] == :delete
124:     end
flash() click to toggle source

Access the contents of the flash. Use flash["notice"] to read a notice you put there or flash["notice"] = "hello" to put a new one.

   # File lib/action_dispatch/middleware/flash.rb, line 6
6:     def flash
7:       @env['action_dispatch.request.flash_hash'] ||= (session["flash"] || Flash::FlashHash.new)
8:     end
forgery_whitelisted?() click to toggle source
     # File lib/action_dispatch/http/request.rb, line 143
143:     def forgery_whitelisted?
144:       get? || xhr? || content_mime_type.nil? || !content_mime_type.verify_request?
145:     end
form_data?() click to toggle source
     # File lib/action_dispatch/http/request.rb, line 208
208:     def form_data?
209:       FORM_DATA_MEDIA_TYPES.include?(content_mime_type.to_s)
210:     end
fullpath() click to toggle source
     # File lib/action_dispatch/http/request.rb, line 139
139:     def fullpath
140:       @fullpath ||= super
141:     end
get?() click to toggle source

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

     # File lib/action_dispatch/http/request.rb, line 104
104:     def get?
105:       HTTP_METHOD_LOOKUP[request_method] == :get
106:     end
head?() click to toggle source

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

     # File lib/action_dispatch/http/request.rb, line 128
128:     def head?
129:       HTTP_METHOD_LOOKUP[method] == :head
130:     end
headers() click to toggle source

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

  request.headers["Content-Type"] # => "text/plain"
     # File lib/action_dispatch/http/request.rb, line 135
135:     def headers
136:       Http::Headers.new(@env)
137:     end
ip() click to toggle source
     # File lib/action_dispatch/http/request.rb, line 164
164:     def ip
165:       @ip ||= super
166:     end
key?(key) click to toggle source
    # File lib/action_dispatch/http/request.rb, line 44
44:     def key?(key)
45:       @env.key?(key)
46:     end
local?() click to toggle source

True if the request came from localhost, 127.0.0.1.

     # File lib/action_dispatch/http/request.rb, line 255
255:     def local?
256:       LOCALHOST.any? { |local_ip| local_ip === remote_addr && local_ip === remote_ip }
257:     end
media_type() click to toggle source
     # File lib/action_dispatch/http/request.rb, line 147
147:     def media_type
148:       content_mime_type.to_s
149:     end
method() click to toggle source

Returns the original value of the environment’s REQUEST_METHOD, even if it was overridden by middleware. See # for more information.

    # File lib/action_dispatch/http/request.rb, line 89
89:     def method
90:       @method ||= begin
91:         method = env["rack.methodoverride.original_method"] || env['REQUEST_METHOD']
92:         HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
93:         method
94:       end
95:     end
method_symbol() click to toggle source

Returns a symbol form of the #

     # File lib/action_dispatch/http/request.rb, line 98
 98:     def method_symbol
 99:       HTTP_METHOD_LOOKUP[method]
100:     end
post?() click to toggle source

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

     # File lib/action_dispatch/http/request.rb, line 110
110:     def post?
111:       HTTP_METHOD_LOOKUP[request_method] == :post
112:     end
put?() click to toggle source

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

     # File lib/action_dispatch/http/request.rb, line 116
116:     def put?
117:       HTTP_METHOD_LOOKUP[request_method] == :put
118:     end
query_parameters() click to toggle source
Alias for: GET
raw_post() click to toggle source

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

     # File lib/action_dispatch/http/request.rb, line 189
189:     def raw_post
190:       unless @env.include? 'RAW_POST_DATA'
191:         @env['RAW_POST_DATA'] = body.read(@env['CONTENT_LENGTH'].to_i)
192:         body.rewind if body.respond_to?(:rewind)
193:       end
194:       @env['RAW_POST_DATA']
195:     end
remote_ip() click to toggle source

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 lib/action_dispatch/http/request.rb, line 178
178:     def remote_ip
179:       @remote_ip ||= (@env["action_dispatch.remote_ip"] || ip).to_s
180:     end
request_method() click to toggle source

Returns the HTTP method that the application should see. In the case where the method was overridden by a middleware (for instance, if a HEAD request was converted to a GET, or if a _method parameter was used to determine the method the application should use), this method returns the overridden value, not the original.

    # File lib/action_dispatch/http/request.rb, line 73
73:     def request_method
74:       @request_method ||= begin
75:         method = env["REQUEST_METHOD"]
76:         HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
77:         method
78:       end
79:     end
request_method_symbol() click to toggle source

Returns a symbol form of the #

    # File lib/action_dispatch/http/request.rb, line 82
82:     def request_method_symbol
83:       HTTP_METHOD_LOOKUP[request_method]
84:     end
request_parameters() click to toggle source
Alias for: POST
reset_session() click to toggle source

TODO This should be broken apart into AD::Request::Session and probably be included by the session middleware.

     # File lib/action_dispatch/http/request.rb, line 218
218:     def reset_session
219:       session.destroy if session
220:       self.session = {}
221:       @env['action_dispatch.request.flash_hash'] = nil
222:     end
server_software() click to toggle source

Returns the lowercase name of the HTTP server software.

     # File lib/action_dispatch/http/request.rb, line 183
183:     def server_software
184:       (@env['SERVER_SOFTWARE'] && /^([a-zA-Z]+)/ =~ @env['SERVER_SOFTWARE']) ? $1.downcase : nil
185:     end
session_options=(options) click to toggle source
     # File lib/action_dispatch/http/request.rb, line 228
228:     def session_options=(options)
229:       @env['rack.session.options'] = options
230:     end
xhr?() click to toggle source
Alias for: xml_http_request?
xml_http_request?() click to toggle source

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

     # File lib/action_dispatch/http/request.rb, line 159
159:     def xml_http_request?
160:       !(@env['HTTP_X_REQUESTED_WITH'] !~ /XMLHttpRequest/)
161:     end
Also aliased as: xhr?

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.