lib/rack/request.rb in rack-0.1.0 vs lib/rack/request.rb in rack-0.2.0

- old
+ new

@@ -6,15 +6,15 @@ # constructor will be directly modified. # # req = Rack::Request.new(env) # req.post? # req.params["data"] - + class Request # The environment of the request. attr_reader :env - + def initialize(env) @env = env end def body; @env["rack.input"] end @@ -57,11 +57,11 @@ if @env["rack.request.form_input"] == @env["rack.input"] @env["rack.request.form_hash"] else @env["rack.request.form_input"] = @env["rack.input"] unless @env["rack.request.form_hash"] = - Utils::Multipart.parse_multipart(env) + Utils::Multipart.parse_multipart(env) @env["rack.request.form_vars"] = @env["rack.input"].read @env["rack.request.form_hash"] = Utils.parse_query(@env["rack.request.form_vars"]) end @env["rack.request.form_hash"] end @@ -70,10 +70,32 @@ # The union of GET and POST data. def params self.GET.update(self.POST) end + # shortcut for request.params[key] + def [](key) + params[key.to_s] + end + + # shortcut for request.params[key] = value + def []=(key, value) + params[key.to_s] = value + end + + # like Hash#values_at + def values_at(*keys) + keys.map{|key| params[key] } + end + + # the referer of the client or '/' + def referer + @env['HTTP_REFERER'] || '/' + end + alias referrer referer + + def cookies return {} unless @env["HTTP_COOKIE"] if @env["rack.request.cookie_string"] == @env["HTTP_COOKIE"] @env["rack.request.cookie_hash"] @@ -97,16 +119,17 @@ if scheme == "https" && port != 443 || scheme == "http" && port != 80 url << ":#{port}" end - url << script_name - url << path_info + url << fullpath - unless query_string.empty? - url << "?" << query_string - end - url + end + + def fullpath + path = script_name + path_info + path << "?" << query_string unless query_string.empty? + path end end end