1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

do not add common ports to HTTP_HOST

- webservers do not do it
 - it makes redirect urls ugly when request.host is used for redirection
This commit is contained in:
Michael Grosser 2015-08-06 17:22:22 -07:00
parent 07b2ff03d0
commit a278630f5f
2 changed files with 24 additions and 1 deletions

View file

@ -325,7 +325,11 @@ module ActionDispatch
if path =~ %r{://}
location = URI.parse(path)
https! URI::HTTPS === location if location.scheme
host! "#{location.host}:#{location.port}" if location.host
if url_host = location.host
default = Rack::Request::DEFAULT_PORTS[location.scheme]
url_host += ":#{location.port}" if default != location.port
host! url_host
end
path = location.query ? "#{location.path}?#{location.query}" : location.path
end

View file

@ -755,6 +755,25 @@ class MetalIntegrationTest < ActionDispatch::IntegrationTest
assert_equal "http://test.com/", @request.env["HTTP_REFERER"]
end
def test_ignores_common_ports_in_host
get "http://test.com"
assert_equal "test.com", @request.env["HTTP_HOST"]
get "https://test.com"
assert_equal "test.com", @request.env["HTTP_HOST"]
end
def test_keeps_uncommon_ports_in_host
get "http://test.com:123"
assert_equal "test.com:123", @request.env["HTTP_HOST"]
get "http://test.com:443"
assert_equal "test.com:443", @request.env["HTTP_HOST"]
get "https://test.com:80"
assert_equal "test.com:80", @request.env["HTTP_HOST"]
end
end
class ApplicationIntegrationTest < ActionDispatch::IntegrationTest