Skip to content
Browse files

Add Request#fullpath

darcs-hash:20070330131207-4fc50-87a99ab267b2d73ae6b59623b5d98a6a325f233b.gz
  • Loading branch information...
1 parent 4abfcfc commit 234c062f746743064bc7808cf04684914a9e3e83 @chneukirchen committed
Showing with 25 additions and 6 deletions.
  1. +7 −6 lib/rack/request.rb
  2. +18 −0 test/spec_rack_request.rb
View
13 lib/rack/request.rb
@@ -99,14 +99,15 @@ def url
url << ":#{port}"
end
- url << script_name
- url << path_info
-
- unless query_string.empty?
- url << "?" << query_string
- end
+ url << fullpath
url
end
+
+ def fullpath
+ path = script_name + path_info
+ path << "?" << query_string unless query_string.empty?
+ path
+ end
end
end
View
18 test/spec_rack_request.rb
@@ -123,6 +123,24 @@
should.equal "https://example.com:8080/foo?foo"
end
+ specify "can restore the full path" do
+ Rack::Request.new(Rack::MockRequest.env_for("")).fullpath.
+ should.equal "/"
+ Rack::Request.new(Rack::MockRequest.env_for("", "SCRIPT_NAME" => "/foo")).fullpath.
+ should.equal "/foo/"
+ Rack::Request.new(Rack::MockRequest.env_for("/foo")).fullpath.
+ should.equal "/foo"
+ Rack::Request.new(Rack::MockRequest.env_for("?foo")).fullpath.
+ should.equal "/?foo"
+ Rack::Request.new(Rack::MockRequest.env_for("http://example.org:8080/")).fullpath.
+ should.equal "/"
+ Rack::Request.new(Rack::MockRequest.env_for("https://example.org/")).fullpath.
+ should.equal "/"
+
+ Rack::Request.new(Rack::MockRequest.env_for("https://example.com:8080/foo?foo")).fullpath.
+ should.equal "/foo?foo"
+ end
+
specify "can parse multipart form data" do
# Adapted from RFC 1867.
input = <<EOF

0 comments on commit 234c062

Please sign in to comment.
Something went wrong with that request. Please try again.