Class | Rack::Request |
In: |
lib/rack/request.rb
|
Parent: | 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"]
env | [R] | The environment of the request. |
Returns the data recieved in the query string.
# File lib/rack/request.rb, line 42 42: def GET 43: if @env["rack.request.query_string"] == query_string 44: @env["rack.request.query_hash"] 45: else 46: @env["rack.request.query_string"] = query_string 47: @env["rack.request.query_hash"] = 48: Utils.parse_query(query_string) 49: end 50: 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 56 56: def POST 57: if @env["rack.request.form_input"] == @env["rack.input"] 58: @env["rack.request.form_hash"] 59: else 60: @env["rack.request.form_input"] = @env["rack.input"] 61: unless @env["rack.request.form_hash"] = 62: Utils::Multipart.parse_multipart(env) 63: @env["rack.request.form_vars"] = @env["rack.input"].read 64: @env["rack.request.form_hash"] = Utils.parse_query(@env["rack.request.form_vars"]) 65: end 66: @env["rack.request.form_hash"] 67: end 68: end
# File lib/rack/request.rb, line 75 75: def cookies 76: return {} unless @env["HTTP_COOKIE"] 77: 78: if @env["rack.request.cookie_string"] == @env["HTTP_COOKIE"] 79: @env["rack.request.cookie_hash"] 80: else 81: @env["rack.request.cookie_string"] = @env["HTTP_COOKIE"] 82: # XXX sure? 83: @env["rack.request.cookie_hash"] = 84: Utils.parse_query(@env["rack.request.cookie_string"], ';,') 85: end 86: end
# File lib/rack/request.rb, line 28 28: def host 29: # Remove port number. 30: (@env["HTTP_HOST"] || @env["SERVER_NAME"]).gsub(/:\d+\z/, '') 31: end
Tries to return a remake of the original request URL as a string.
# File lib/rack/request.rb, line 93 93: def url 94: url = scheme + "://" 95: url << host 96: 97: if scheme == "https" && port != 443 || 98: scheme == "http" && port != 80 99: url << ":#{port}" 100: end 101: 102: url << script_name 103: url << path_info 104: 105: unless query_string.empty? 106: url << "?" << query_string 107: end 108: 109: url 110: end