Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not add common ports to HTTP_HOST #21153

Merged
merged 1 commit into from
Aug 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion actionpack/lib/action_dispatch/testing/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,11 @@ def process(method, path, params: nil, headers: nil, env: nil, xhr: false)
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

Expand Down
19 changes: 19 additions & 0 deletions actionpack/test/controller/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,25 @@ def test_pass_env
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
Expand Down