Object
Rack::Request provides a convenient interface to a Rack environment. It is stateless, the environment env passed to the constructor will be directly modified.
req = Rack::Request.new(env) req.post? req.params["data"]
The environment hash passed will store a reference to the Request object instantiated so that it will only instantiate if an instance of the Request object doesn’t already exist.
The set of form-data media-types. Requests that do not indicate one of the media types presents in this list will not be eligible for form-data / param parsing.
The set of media-types. Requests that do not indicate one of the media types presents in this list will not be eligible for param parsing like soap attachments or generic multiparts
Returns the data recieved in the query string.
# File lib/rack/request.rb, line 121 121: def GET 122: if @env["rack.request.query_string"] == query_string 123: @env["rack.request.query_hash"] 124: else 125: @env["rack.request.query_string"] = query_string 126: @env["rack.request.query_hash"] = 127: Utils.parse_nested_query(query_string) 128: end 129: end
Returns the data recieved in the request body.
This method support both application/x-www-form-urlencoded and multipart/form-data.
# File lib/rack/request.rb, line 135 135: def POST 136: if @env["rack.request.form_input"].eql? @env["rack.input"] 137: @env["rack.request.form_hash"] 138: elsif form_data? || parseable_data? 139: @env["rack.request.form_input"] = @env["rack.input"] 140: unless @env["rack.request.form_hash"] = 141: Utils::Multipart.parse_multipart(env) 142: form_vars = @env["rack.input"].read 143: 144: # Fix for Safari Ajax postings that always append \0 145: form_vars.sub!(/\0\z/, '') 146: 147: @env["rack.request.form_vars"] = form_vars 148: @env["rack.request.form_hash"] = Utils.parse_nested_query(form_vars) 149: 150: @env["rack.input"].rewind 151: end 152: @env["rack.request.form_hash"] 153: else 154: {} 155: end 156: end
shortcut for request.params[key]
# File lib/rack/request.rb, line 166 166: def [](key) 167: params[key.to_s] 168: end
shortcut for request.params[key] = value
# File lib/rack/request.rb, line 171 171: def []=(key, value) 172: params[key.to_s] = value 173: end
(Not documented)
# File lib/rack/request.rb, line 234 234: def accept_encoding 235: @env["HTTP_ACCEPT_ENCODING"].to_s.split(/,\s*/).map do |part| 236: m = /^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$/.match(part) # From WEBrick 237: 238: if m 239: [m[1], (m[2] || 1.0).to_f] 240: else 241: raise "Invalid value for Accept-Encoding: #{part.inspect}" 242: end 243: end 244: end
(Not documented)
# File lib/rack/request.rb, line 32 32: def body; @env["rack.input"] end
The character set of the request body if a “charset” media type parameter was given, or nil if no “charset” was specified. Note that, per RFC2616, text/* media types that specify no explicit charset are to be considered ISO-8859-1.
# File lib/rack/request.rb, line 70 70: def content_charset 71: media_type_params['charset'] 72: end
(Not documented)
# File lib/rack/request.rb, line 39 39: def content_length; @env['CONTENT_LENGTH'] end
(Not documented)
# File lib/rack/request.rb, line 40 40: def content_type; @env['CONTENT_TYPE'] end
(Not documented)
# File lib/rack/request.rb, line 85 85: def delete?; request_method == "DELETE" end
Determine whether the request body contains form-data by checking the request media_type against registered form-data media-types: “application/x-www-form-urlencoded” and “multipart/form-data”. The list of form-data media types can be modified through the FORM_DATA_MEDIA_TYPES array.
# File lib/rack/request.rb, line 110 110: def form_data? 111: FORM_DATA_MEDIA_TYPES.include?(media_type) 112: end
(Not documented)
# File lib/rack/request.rb, line 230 230: def fullpath 231: query_string.empty? ? path : "#{path}?#{query_string}" 232: end
(Not documented)
# File lib/rack/request.rb, line 82 82: def get?; request_method == "GET" end
(Not documented)
# File lib/rack/request.rb, line 86 86: def head?; request_method == "HEAD" end
(Not documented)
# File lib/rack/request.rb, line 74 74: def host 75: # Remove port number. 76: (@env["HTTP_HOST"] || @env["SERVER_NAME"]).gsub(/:\d+\z/, '') 77: end
(Not documented)
# File lib/rack/request.rb, line 246 246: def ip 247: if addr = @env['HTTP_X_FORWARDED_FOR'] 248: addr.split(',').last.strip 249: else 250: @env['REMOTE_ADDR'] 251: end 252: end
The media type (type/subtype) portion of the CONTENT_TYPE header without any media type parameters. e.g., when CONTENT_TYPE is “text/plain;charset=utf-8”, the media-type is “text/plain“.
For more information on the use of media types in HTTP, see: www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7
# File lib/rack/request.rb, line 50 50: def media_type 51: content_type && content_type.split(/\s*[;,]\s*/, 2).first.downcase 52: end
The media type parameters provided in CONTENT_TYPE as a Hash, or an empty Hash if no CONTENT_TYPE or media-type parameters were provided. e.g., when the CONTENT_TYPE is “text/plain;charset=utf-8”, this method responds with the following Hash:
{ 'charset' => 'utf-8' }
# File lib/rack/request.rb, line 59 59: def media_type_params 60: return {} if content_type.nil? 61: content_type.split(/\s*[;,]\s*/)[1..-1]. 62: collect { |s| s.split('=', 2) }. 63: inject({}) { |hash,(k,v)| hash[k.downcase] = v ; hash } 64: end
(Not documented)
# File lib/rack/auth/openid.rb, line 14 14: def openid_request 15: @env['rack.auth.openid.request'] 16: end
(Not documented)
# File lib/rack/auth/openid.rb, line 18 18: def openid_response 19: @env['rack.auth.openid.response'] 20: end
Determine whether the request body contains data by checking the request media_type against registered parse-data media-types
# File lib/rack/request.rb, line 116 116: def parseable_data? 117: PARSEABLE_DATA_MEDIA_TYPES.include?(media_type) 118: end
(Not documented)
# File lib/rack/request.rb, line 226 226: def path 227: script_name + path_info 228: end
(Not documented)
# File lib/rack/request.rb, line 35 35: def path_info; @env["PATH_INFO"].to_s end
(Not documented)
# File lib/rack/request.rb, line 80 80: def path_info=(s); @env["PATH_INFO"] = s.to_s end
(Not documented)
# File lib/rack/request.rb, line 36 36: def port; @env["SERVER_PORT"].to_i end
(Not documented)
# File lib/rack/request.rb, line 83 83: def post?; request_method == "POST" end
(Not documented)
# File lib/rack/request.rb, line 84 84: def put?; request_method == "PUT" end
(Not documented)
# File lib/rack/request.rb, line 38 38: def query_string; @env["QUERY_STRING"].to_s end
the referer of the client or ’/’
# File lib/rack/request.rb, line 181 181: def referer 182: @env['HTTP_REFERER'] || '/' 183: end
(Not documented)
# File lib/rack/request.rb, line 37 37: def request_method; @env["REQUEST_METHOD"] end
(Not documented)
# File lib/rack/request.rb, line 33 33: def scheme; @env["rack.url_scheme"] end
(Not documented)
# File lib/rack/request.rb, line 34 34: def script_name; @env["SCRIPT_NAME"].to_s end
(Not documented)
# File lib/rack/request.rb, line 79 79: def script_name=(s); @env["SCRIPT_NAME"] = s.to_s end
(Not documented)
# File lib/rack/request.rb, line 41 41: def session; @env['rack.session'] ||= {} end
(Not documented)
# File lib/rack/request.rb, line 42 42: def session_options; @env['rack.session.options'] ||= {} end
Tries to return a remake of the original request URL as a string.
# File lib/rack/request.rb, line 212 212: def url 213: url = scheme + "://" 214: url << host 215: 216: if scheme == "https" && port != 443 || 217: scheme == "http" && port != 80 218: url << ":#{port}" 219: end 220: 221: url << fullpath 222: 223: url 224: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.