Skip to content

Commit

Permalink
correct Request#port for lighttpd2 proxy case
Browse files Browse the repository at this point in the history
  • Loading branch information
manveru authored and bf4 committed Jul 9, 2014
1 parent ac590d0 commit f3a378d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rack/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def port
port.to_i
elsif @env.has_key?("HTTP_X_FORWARDED_HOST")
DEFAULT_PORTS[scheme]
elsif @env.has_key?("HTTP_X_FORWARDED_PROTO")
DEFAULT_PORTS[@env['HTTP_X_FORWARDED_PROTO']]
else
@env["SERVER_PORT"].to_i
end
Expand Down
5 changes: 5 additions & 0 deletions test/spec_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@
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

req = Rack::Request.new \
Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost", "HTTP_X_FORWARDED_PROTO" => "https", "SERVER_PORT" => "80")

req.port.should.equal 443
end

should "figure out the correct host with port" do
Expand Down

0 comments on commit f3a378d

Please sign in to comment.