Parent

Class Index [+]

Quicksearch

ActionDispatch::Request

Constants

LOCALHOST
ENV_METHODS
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

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 224
224:     def GET
225:       @env["action_dispatch.request.query_parameters"] ||= (normalize_parameters(super) || {})
226:     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 230
230:     def POST
231:       @env["action_dispatch.request.request_parameters"] ||= (normalize_parameters(super) || {})
232:     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 238
238:     def authorization
239:       @env['HTTP_AUTHORIZATION']   ||
240:       @env['X-HTTP_AUTHORIZATION'] ||
241:       @env['X_HTTP_AUTHORIZATION'] ||
242:       @env['REDIRECT_X_HTTP_AUTHORIZATION']
243:     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 190
190:     def body
191:       if raw_post = @env['RAW_POST_DATA']
192:         raw_post.force_encoding(Encoding::BINARY) if raw_post.respond_to?(:force_encoding)
193:         StringIO.new(raw_post)
194:       else
195:         @env['rack.input']
196:       end
197:     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 142
142:     def content_length
143:       super.to_i
144:     end
delete?() click to toggle source

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

     # File lib/action_dispatch/http/request.rb, line 108
108:     def delete?
109:       HTTP_METHOD_LOOKUP[request_method] == :delete
110:     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[Flash::KEY] ||= (session["flash"] || Flash::FlashHash.new)
8:     end
form_data?() click to toggle source
     # File lib/action_dispatch/http/request.rb, line 199
199:     def form_data?
200:       FORM_DATA_MEDIA_TYPES.include?(content_mime_type.to_s)
201:     end
fullpath() click to toggle source
     # File lib/action_dispatch/http/request.rb, line 129
129:     def fullpath
130:       @fullpath ||= super
131:     end
get?() click to toggle source

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

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

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

     # File lib/action_dispatch/http/request.rb, line 114
114:     def head?
115:       HTTP_METHOD_LOOKUP[method] == :head
116:     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 121
121:     def headers
122:       Http::Headers.new(@env)
123:     end
ip() click to toggle source
     # File lib/action_dispatch/http/request.rb, line 154
154:     def ip
155:       @ip ||= super
156:     end
key?(key) click to toggle source
    # File lib/action_dispatch/http/request.rb, line 38
38:     def key?(key)
39:       @env.key?(key)
40:     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 246
246:     def local?
247:       LOCALHOST.any? { |local_ip| local_ip === remote_addr && local_ip === remote_ip }
248:     end
media_type() click to toggle source
     # File lib/action_dispatch/http/request.rb, line 137
137:     def media_type
138:       content_mime_type.to_s
139:     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 79
79:     def method
80:       @method ||= check_method(env["rack.methodoverride.original_method"] || env['REQUEST_METHOD'])
81:     end
method_symbol() click to toggle source

Returns a symbol form of the #

    # File lib/action_dispatch/http/request.rb, line 84
84:     def method_symbol
85:       HTTP_METHOD_LOOKUP[method]
86:     end
original_fullpath() click to toggle source
     # File lib/action_dispatch/http/request.rb, line 125
125:     def original_fullpath
126:       @original_fullpath ||= (env["ORIGINAL_FULLPATH"] || fullpath)
127:     end
original_url() click to toggle source
     # File lib/action_dispatch/http/request.rb, line 133
133:     def original_url
134:       base_url + original_fullpath
135:     end
post?() click to toggle source

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

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

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

     # File lib/action_dispatch/http/request.rb, line 102
102:     def put?
103:       HTTP_METHOD_LOOKUP[request_method] == :put
104:     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 180
180:     def raw_post
181:       unless @env.include? 'RAW_POST_DATA'
182:         @env['RAW_POST_DATA'] = body.read(@env['CONTENT_LENGTH'].to_i)
183:         body.rewind if body.respond_to?(:rewind)
184:       end
185:       @env['RAW_POST_DATA']
186:     end
remote_ip() click to toggle source

Originating IP address, usually set by the RemoteIp middleware.

     # File lib/action_dispatch/http/request.rb, line 159
159:     def remote_ip
160:       @remote_ip ||= (@env["action_dispatch.remote_ip"] || ip).to_s
161:     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 67
67:     def request_method
68:       @request_method ||= check_method(env["REQUEST_METHOD"])
69:     end
request_method_symbol() click to toggle source

Returns a symbol form of the #

    # File lib/action_dispatch/http/request.rb, line 72
72:     def request_method_symbol
73:       HTTP_METHOD_LOOKUP[request_method]
74:     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 209
209:     def reset_session
210:       session.destroy if session && session.respond_to?(:destroy)
211:       self.session = {}
212:       @env['action_dispatch.request.flash_hash'] = nil
213:     end
server_software() click to toggle source

Returns the lowercase name of the HTTP server software.

     # File lib/action_dispatch/http/request.rb, line 174
174:     def server_software
175:       (@env['SERVER_SOFTWARE'] && /^([a-zA-Z]+)/ =~ @env['SERVER_SOFTWARE']) ? $1.downcase : nil
176:     end
session_options=(options) click to toggle source
     # File lib/action_dispatch/http/request.rb, line 219
219:     def session_options=(options)
220:       @env['rack.session.options'] = options
221:     end
uuid() click to toggle source

Returns the unique request id, which is based off either the X-Request-Id header that can be generated by a firewall, load balancer, or web server or by the RequestId middleware (which sets the action_dispatch.request_id environment variable).

This unique ID is useful for tracing a request from end-to-end as part of logging or debugging. This relies on the rack variable set by the ActionDispatch::RequestId middleware.

     # File lib/action_dispatch/http/request.rb, line 169
169:     def uuid
170:       @uuid ||= env["action_dispatch.request_id"]
171:     end
xhr?() click to toggle source
Alias for: xml_http_request?
xml_http_request?() click to toggle source

Returns true if the “X-Requested-With” header contains “XMLHttpRequest” (case-insensitive). All major JavaScript libraries send this header with every Ajax request.

     # File lib/action_dispatch/http/request.rb, line 149
149:     def xml_http_request?
150:       @env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/
151:     end
Also aliased as: xhr?

Protected Instance Methods

deep_munge(hash) click to toggle source

Remove nils from the params hash

     # File lib/action_dispatch/http/request.rb, line 253
253:     def deep_munge(hash)
254:       keys = hash.keys.find_all { |k| hash[k] == [nil] }
255:       keys.each { |k| hash[k] = nil }
256: 
257:       hash.each_value do |v|
258:         case v
259:         when Array
260:           v.grep(Hash) { |x| deep_munge(x) }
261:           v.compact!
262:         when Hash
263:           deep_munge(v)
264:         end
265:       end
266: 
267:       hash
268:     end
parse_query(qs) click to toggle source
     # File lib/action_dispatch/http/request.rb, line 270
270:     def parse_query(qs)
271:       deep_munge(super)
272:     end

Private Instance Methods

check_method(name) click to toggle source
     # File lib/action_dispatch/http/request.rb, line 276
276:     def check_method(name)
277:       HTTP_METHOD_LOOKUP[name] || raise(ActionController::UnknownHttpMethod, "#{name}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
278:       name
279:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.