Methods
G
P
A
B
C
D
F
G
H
I
K
L
M
O
P
Q
R
S
U
X
Included Modules
Constants
LOCALHOST = [/^127\.0\.0\.\d{1,3}$/, "::1", /^0:0:0:0:0:0:0:1(%.*)?$/].freeze
ENV_METHODS = %w[ AUTH_TYPE GATEWAY_INTERFACE PATH_TRANSLATED REMOTE_HOST REMOTE_IDENT REMOTE_USER REMOTE_ADDR SERVER_NAME SERVER_PROTOCOL HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_ACCEPT_ENCODING HTTP_ACCEPT_LANGUAGE HTTP_CACHE_CONTROL HTTP_FROM HTTP_NEGOTIATE HTTP_PRAGMA ].freeze
RFC2616 = %w(OPTIONS GET HEAD POST PUT DELETE TRACE CONNECT)
 

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 = %w(PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK)
RFC3253 = %w(VERSION-CONTROL REPORT CHECKOUT CHECKIN UNCHECKOUT MKWORKSPACE UPDATE LABEL MERGE BASELINE-CONTROL MKACTIVITY)
RFC3648 = %w(ORDERPATCH)
RFC3744 = %w(ACL)
RFC5323 = %w(SEARCH)
RFC5789 = %w(PATCH)
HTTP_METHODS = RFC2616 + RFC2518 + RFC3253 + RFC3648 + RFC3744 + RFC5323 + RFC5789
HTTP_METHOD_LOOKUP = Hash.new { |h, m| h[m] = m.underscore.to_sym if HTTP_METHODS.include?(m) }
Instance Public methods
GET()

Override Rack’s GET method to support indifferent access

This method is also aliased as query_parameters
     # File actionpack/lib/action_dispatch/http/request.rb, line 225
225:     def GET
226:       @env["action_dispatch.request.query_parameters"] ||= (normalize_parameters(super) || {})
227:     end
POST()

Override Rack’s POST method to support indifferent access

This method is also aliased as request_parameters
     # File actionpack/lib/action_dispatch/http/request.rb, line 231
231:     def POST
232:       @env["action_dispatch.request.request_parameters"] ||= (normalize_parameters(super) || {})
233:     end
authorization()

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

     # File actionpack/lib/action_dispatch/http/request.rb, line 239
239:     def authorization
240:       @env['HTTP_AUTHORIZATION']   ||
241:       @env['X-HTTP_AUTHORIZATION'] ||
242:       @env['X_HTTP_AUTHORIZATION'] ||
243:       @env['REDIRECT_X_HTTP_AUTHORIZATION']
244:     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 actionpack/lib/action_dispatch/http/request.rb, line 191
191:     def body
192:       if raw_post = @env['RAW_POST_DATA']
193:         raw_post.force_encoding(Encoding::BINARY) if raw_post.respond_to?(:force_encoding)
194:         StringIO.new(raw_post)
195:       else
196:         @env['rack.input']
197:       end
198:     end
content_length()

Returns the content length of the request as an integer.

     # File actionpack/lib/action_dispatch/http/request.rb, line 143
143:     def content_length
144:       super.to_i
145:     end
cookie_jar()
   # File actionpack/lib/action_dispatch/middleware/cookies.rb, line 6
6:     def cookie_jar
7:       env['action_dispatch.cookies'] ||= Cookies::CookieJar.build(self)
8:     end
delete?()

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

     # File actionpack/lib/action_dispatch/http/request.rb, line 109
109:     def delete?
110:       HTTP_METHOD_LOOKUP[request_method] == :delete
111:     end
flash()

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 actionpack/lib/action_dispatch/middleware/flash.rb, line 6
6:     def flash
7:       @env[Flash::KEY] ||= (session["flash"] || Flash::FlashHash.new)
8:     end
form_data?()
     # File actionpack/lib/action_dispatch/http/request.rb, line 200
200:     def form_data?
201:       FORM_DATA_MEDIA_TYPES.include?(content_mime_type.to_s)
202:     end
fullpath()
     # File actionpack/lib/action_dispatch/http/request.rb, line 130
130:     def fullpath
131:       @fullpath ||= super
132:     end
get?()

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

    # File actionpack/lib/action_dispatch/http/request.rb, line 91
91:     def get?
92:       HTTP_METHOD_LOOKUP[request_method] == :get
93:     end
head?()

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

     # File actionpack/lib/action_dispatch/http/request.rb, line 115
115:     def head?
116:       HTTP_METHOD_LOOKUP[method] == :head
117:     end
headers()

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

  request.headers["Content-Type"] # => "text/plain"
     # File actionpack/lib/action_dispatch/http/request.rb, line 122
122:     def headers
123:       Http::Headers.new(@env)
124:     end
ip()
     # File actionpack/lib/action_dispatch/http/request.rb, line 155
155:     def ip
156:       @ip ||= super
157:     end
key?(key)
    # File actionpack/lib/action_dispatch/http/request.rb, line 39
39:     def key?(key)
40:       @env.key?(key)
41:     end
local?()

True if the request came from localhost, 127.0.0.1.

     # File actionpack/lib/action_dispatch/http/request.rb, line 247
247:     def local?
248:       LOCALHOST.any? { |local_ip| local_ip === remote_addr && local_ip === remote_ip }
249:     end
media_type()
     # File actionpack/lib/action_dispatch/http/request.rb, line 138
138:     def media_type
139:       content_mime_type.to_s
140:     end
method()

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

    # File actionpack/lib/action_dispatch/http/request.rb, line 80
80:     def method
81:       @method ||= check_method(env["rack.methodoverride.original_method"] || env['REQUEST_METHOD'])
82:     end
method_symbol()

Returns a symbol form of the method

    # File actionpack/lib/action_dispatch/http/request.rb, line 85
85:     def method_symbol
86:       HTTP_METHOD_LOOKUP[method]
87:     end
original_fullpath()
     # File actionpack/lib/action_dispatch/http/request.rb, line 126
126:     def original_fullpath
127:       @original_fullpath ||= (env["ORIGINAL_FULLPATH"] || fullpath)
128:     end
original_url()
     # File actionpack/lib/action_dispatch/http/request.rb, line 134
134:     def original_url
135:       base_url + original_fullpath
136:     end
post?()

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

    # File actionpack/lib/action_dispatch/http/request.rb, line 97
97:     def post?
98:       HTTP_METHOD_LOOKUP[request_method] == :post
99:     end
put?()

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

     # File actionpack/lib/action_dispatch/http/request.rb, line 103
103:     def put?
104:       HTTP_METHOD_LOOKUP[request_method] == :put
105:     end
query_parameters()

Alias for GET

raw_post()

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

     # File actionpack/lib/action_dispatch/http/request.rb, line 181
181:     def raw_post
182:       unless @env.include? 'RAW_POST_DATA'
183:         @env['RAW_POST_DATA'] = body.read(@env['CONTENT_LENGTH'].to_i)
184:         body.rewind if body.respond_to?(:rewind)
185:       end
186:       @env['RAW_POST_DATA']
187:     end
remote_ip()

Originating IP address, usually set by the RemoteIp middleware.

     # File actionpack/lib/action_dispatch/http/request.rb, line 160
160:     def remote_ip
161:       @remote_ip ||= (@env["action_dispatch.remote_ip"] || ip).to_s
162:     end
request_method()

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 actionpack/lib/action_dispatch/http/request.rb, line 68
68:     def request_method
69:       @request_method ||= check_method(env["REQUEST_METHOD"])
70:     end
request_method_symbol()

Returns a symbol form of the request_method

    # File actionpack/lib/action_dispatch/http/request.rb, line 73
73:     def request_method_symbol
74:       HTTP_METHOD_LOOKUP[request_method]
75:     end
request_parameters()

Alias for POST

reset_session()

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

     # File actionpack/lib/action_dispatch/http/request.rb, line 210
210:     def reset_session
211:       session.destroy if session && session.respond_to?(:destroy)
212:       self.session = {}
213:       @env['action_dispatch.request.flash_hash'] = nil
214:     end
server_software()

Returns the lowercase name of the HTTP server software.

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

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 actionpack/lib/action_dispatch/http/request.rb, line 170
170:     def uuid
171:       @uuid ||= env["action_dispatch.request_id"]
172:     end
xhr?()

Alias for xml_http_request?

xml_http_request?()

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

This method is also aliased as xhr?
     # File actionpack/lib/action_dispatch/http/request.rb, line 150
150:     def xml_http_request?
151:       @env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i
152:     end
Instance Protected methods
deep_munge(hash)

Remove nils from the params hash

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