Rack::Request
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)
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
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
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
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
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
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
# 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
# File lib/action_dispatch/http/request.rb, line 129 129: def fullpath 130: @fullpath ||= super 131: end
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
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
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
# File lib/action_dispatch/http/request.rb, line 154 154: def ip 155: @ip ||= super 156: end
# File lib/action_dispatch/http/request.rb, line 38 38: def key?(key) 39: @env.key?(key) 40: end
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
# File lib/action_dispatch/http/request.rb, line 137 137: def media_type 138: content_mime_type.to_s 139: end
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
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
# File lib/action_dispatch/http/request.rb, line 125 125: def original_fullpath 126: @original_fullpath ||= (env["ORIGINAL_FULLPATH"] || fullpath) 127: end
# File lib/action_dispatch/http/request.rb, line 133 133: def original_url 134: base_url + original_fullpath 135: end
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
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
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
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
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
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
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
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
# File lib/action_dispatch/http/request.rb, line 219 219: def session_options=(options) 220: @env['rack.session.options'] = options 221: end
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
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
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
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.