Parent

Class Index [+]

Quicksearch

ActionDispatch::Request

Constants

LOCALHOST
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 35
35:     def self.new(env)
36:       if request = env["action_dispatch.request"] && request.instance_of?(self)
37:         return request
38:       end
39: 
40:       super
41:     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 216
216:     def GET
217:       @env["action_dispatch.request.query_parameters"] ||= normalize_parameters(super)
218:     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 222
222:     def POST
223:       @env["action_dispatch.request.request_parameters"] ||= normalize_parameters(super)
224:     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 230
230:     def authorization
231:       @env['HTTP_AUTHORIZATION']   ||
232:       @env['X-HTTP_AUTHORIZATION'] ||
233:       @env['X_HTTP_AUTHORIZATION'] ||
234:       @env['REDIRECT_X_HTTP_AUTHORIZATION']
235:     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 182
182:     def body
183:       if raw_post = @env['RAW_POST_DATA']
184:         raw_post.force_encoding(Encoding::BINARY) if raw_post.respond_to?(:force_encoding)
185:         StringIO.new(raw_post)
186:       else
187:         @env['rack.input']
188:       end
189:     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 135
135:     def content_length
136:       super.to_i
137:     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 105
105:     def delete?
106:       HTTP_METHOD_LOOKUP[request_method] == :delete
107:     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 126
126:     def forgery_whitelisted?
127:       get? || xhr? || content_mime_type.nil? || !content_mime_type.verify_request?
128:     end
form_data?() click to toggle source
     # File lib/action_dispatch/http/request.rb, line 191
191:     def form_data?
192:       FORM_DATA_MEDIA_TYPES.include?(content_mime_type.to_s)
193:     end
fullpath() click to toggle source
     # File lib/action_dispatch/http/request.rb, line 122
122:     def fullpath
123:       @fullpath ||= super
124:     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 87
87:     def get?
88:       HTTP_METHOD_LOOKUP[request_method] == :get
89:     end
head?() click to toggle source

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

     # File lib/action_dispatch/http/request.rb, line 111
111:     def head?
112:       HTTP_METHOD_LOOKUP[method] == :head
113:     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 118
118:     def headers
119:       Http::Headers.new(@env)
120:     end
ip() click to toggle source
     # File lib/action_dispatch/http/request.rb, line 147
147:     def ip
148:       @ip ||= super
149:     end
key?(key) click to toggle source
    # File lib/action_dispatch/http/request.rb, line 43
43:     def key?(key)
44:       @env.key?(key)
45:     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 238
238:     def local?
239:       LOCALHOST.any? { |local_ip| local_ip === remote_addr && local_ip === remote_ip }
240:     end
media_type() click to toggle source
     # File lib/action_dispatch/http/request.rb, line 130
130:     def media_type
131:       content_mime_type.to_s
132:     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 72
72:     def method
73:       @method ||= begin
74:         method = env["rack.methodoverride.original_method"] || env['REQUEST_METHOD']
75:         HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
76:         method
77:       end
78:     end
method_symbol() click to toggle source

Returns a symbol form of the #

    # File lib/action_dispatch/http/request.rb, line 81
81:     def method_symbol
82:       HTTP_METHOD_LOOKUP[method]
83:     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 93
93:     def post?
94:       HTTP_METHOD_LOOKUP[request_method] == :post
95:     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 99
 99:     def put?
100:       HTTP_METHOD_LOOKUP[request_method] == :put
101:     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 172
172:     def raw_post
173:       unless @env.include? 'RAW_POST_DATA'
174:         @env['RAW_POST_DATA'] = body.read(@env['CONTENT_LENGTH'].to_i)
175:         body.rewind if body.respond_to?(:rewind)
176:       end
177:       @env['RAW_POST_DATA']
178:     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 161
161:     def remote_ip
162:       @remote_ip ||= (@env["action_dispatch.remote_ip"] || ip).to_s
163:     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 56
56:     def request_method
57:       @request_method ||= begin
58:         method = env["REQUEST_METHOD"]
59:         HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
60:         method
61:       end
62:     end
request_method_symbol() click to toggle source

Returns a symbol form of the #

    # File lib/action_dispatch/http/request.rb, line 65
65:     def request_method_symbol
66:       HTTP_METHOD_LOOKUP[request_method]
67:     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 201
201:     def reset_session
202:       session.destroy if session
203:       self.session = {}
204:       @env['action_dispatch.request.flash_hash'] = nil
205:     end
server_software() click to toggle source

Returns the lowercase name of the HTTP server software.

     # File lib/action_dispatch/http/request.rb, line 166
166:     def server_software
167:       (@env['SERVER_SOFTWARE'] && /^([a-zA-Z]+)/ =~ @env['SERVER_SOFTWARE']) ? $1.downcase : nil
168:     end
session_options=(options) click to toggle source
     # File lib/action_dispatch/http/request.rb, line 211
211:     def session_options=(options)
212:       @env['rack.session.options'] = options
213:     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 142
142:     def xml_http_request?
143:       !(@env['HTTP_X_REQUESTED_WITH'] !~ /XMLHttpRequest/)
144:     end
Also aliased as: xhr?

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.