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)
Which IP addresses are “trusted proxies” that can be stripped from the right-hand-side of X-Forwarded-For
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
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
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
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
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
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
# 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
# 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
# File lib/action_dispatch/http/request.rb, line 139 139: def fullpath 140: @fullpath ||= super 141: end
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
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
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
# File lib/action_dispatch/http/request.rb, line 164 164: def ip 165: @ip ||= super 166: end
# File lib/action_dispatch/http/request.rb, line 44 44: def key?(key) 45: @env.key?(key) 46: end
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
# File lib/action_dispatch/http/request.rb, line 147 147: def media_type 148: content_mime_type.to_s 149: 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 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
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
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
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
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
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
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
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
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
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
# File lib/action_dispatch/http/request.rb, line 228 228: def session_options=(options) 229: @env['rack.session.options'] = options 230: end
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
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.