mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Make sure that the default port is 80 when the request doesn't include HTTP_X_FORWARDED_PROTO.
This commit is contained in:
parent
1c6c61b089
commit
81461adac0
2 changed files with 21 additions and 3 deletions
|
@ -294,11 +294,11 @@ module Puma
|
|||
env[SERVER_PORT] = host[colon+1, host.bytesize]
|
||||
else
|
||||
env[SERVER_NAME] = host
|
||||
env[SERVER_PORT] = default_server_host_port(env)
|
||||
env[SERVER_PORT] = default_server_port(env)
|
||||
end
|
||||
else
|
||||
env[SERVER_NAME] = LOCALHOST
|
||||
env[SERVER_PORT] = default_server_host_port(env)
|
||||
env[SERVER_PORT] = default_server_port(env)
|
||||
end
|
||||
|
||||
unless env[REQUEST_PATH]
|
||||
|
@ -322,7 +322,7 @@ module Puma
|
|||
env[REMOTE_ADDR] = client.peeraddr.last
|
||||
end
|
||||
|
||||
def default_server_host_port(env)
|
||||
def default_server_port(env)
|
||||
env['HTTP_X_FORWARDED_PROTO'] == 'https' ? PORT_443 : PORT_80
|
||||
end
|
||||
|
||||
|
|
|
@ -144,4 +144,22 @@ class TestPumaServer < Test::Unit::TestCase
|
|||
|
||||
assert_equal "443", res.body
|
||||
end
|
||||
|
||||
def test_default_server_port
|
||||
@server.app = proc do |env|
|
||||
[200, {}, [env['SERVER_PORT']]]
|
||||
end
|
||||
|
||||
@server.add_tcp_listener @host, @port
|
||||
@server.run
|
||||
|
||||
req = Net::HTTP::Get.new("/")
|
||||
req['HOST'] = "example.com"
|
||||
|
||||
res = Net::HTTP.start @host, @port do |http|
|
||||
http.request(req)
|
||||
end
|
||||
|
||||
assert_equal "80", res.body
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue