diff options
-rw-r--r-- | lib/rack/request.rb | 2 | ||||
-rw-r--r-- | test/spec_request.rb | 12 |
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/rack/request.rb b/lib/rack/request.rb index 816640ed..5ebd72ea 100644 --- a/lib/rack/request.rb +++ b/lib/rack/request.rb @@ -98,6 +98,8 @@ module Rack port.to_i elsif ssl? 443 + elsif @env.has_key?("HTTP_X_FORWARDED_HOST") + 80 else @env["SERVER_PORT"].to_i end diff --git a/test/spec_request.rb b/test/spec_request.rb index 6765edca..ddaa172b 100644 --- a/test/spec_request.rb +++ b/test/spec_request.rb @@ -84,6 +84,14 @@ describe Rack::Request do req = Rack::Request.new \ Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost:81", "HTTP_X_FORWARDED_HOST" => "example.org", "HTTP_X_FORWARDED_PORT" => "9393") req.port.should.equal 9393 + + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost:81", "HTTP_X_FORWARDED_HOST" => "example.org:9393", "SERVER_PORT" => "80") + req.port.should.equal 9393 + + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost:81", "HTTP_X_FORWARDED_HOST" => "example.org", "SERVER_PORT" => "9393") + req.port.should.equal 80 end should "figure out the correct host with port" do @@ -102,6 +110,10 @@ describe Rack::Request do req = Rack::Request.new \ Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost:81", "HTTP_X_FORWARDED_HOST" => "example.org:9292") req.host_with_port.should.equal "example.org:9292" + + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost:81", "HTTP_X_FORWARDED_HOST" => "example.org", "SERVER_PORT" => "9393") + req.host_with_port.should.equal "example.org" end should "parse the query string" do |