Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Extract Request#base_url

  • Loading branch information...
commit d7a3bb21684557b55920cc48d6011be528279421 1 parent 66ef0e4
@josh josh authored
Showing with 14 additions and 5 deletions.
  1. +6 −4 lib/rack/request.rb
  2. +8 −1 test/spec_request.rb
View
10 lib/rack/request.rb
@@ -248,8 +248,7 @@ def xhr?
@env["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest"
end
- # Tries to return a remake of the original request URL as a string.
- def url
+ def base_url
url = scheme + "://"
url << host
@@ -258,11 +257,14 @@ def url
url << ":#{port}"
end
- url << fullpath
-
url
end
+ # Tries to return a remake of the original request URL as a string.
+ def url
+ base_url + fullpath
+ end
+
def path
script_name + path_info
end
View
9 test/spec_request.rb
@@ -360,6 +360,13 @@
req.env.should == e
end
+ should "restore the base URL" do
+ Rack::Request.new(Rack::MockRequest.env_for("")).base_url.
+ should.equal "http://example.org"
+ Rack::Request.new(Rack::MockRequest.env_for("", "SCRIPT_NAME" => "/foo")).base_url.
+ should.equal "http://example.org"
+ end
+
should "restore the URL" do
Rack::Request.new(Rack::MockRequest.env_for("")).url.
should.equal "http://example.org/"
@@ -550,7 +557,7 @@
lambda { req.POST }.should.raise(EOFError)
end
-
+
should "correctly parse the part name from Content-Id header" do
input = <<EOF
--AaB03x\r
Please sign in to comment.
Something went wrong with that request. Please try again.