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

Restore: changed behavior for request.host when multiple X-Forwarded-Host are used #1832

Closed
Closed
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
2 changes: 1 addition & 1 deletion lib/rack/request.rb
Expand Up @@ -359,7 +359,7 @@ def forwarded_port

def forwarded_authority
if value = get_header(HTTP_X_FORWARDED_HOST)
wrap_ipv6(split_header(value).first)
wrap_ipv6(split_header(value).last)
end
end

Expand Down
5 changes: 5 additions & 0 deletions test/spec_request.rb
Expand Up @@ -167,6 +167,11 @@ class RackRequestTest < Minitest::Spec
req.host.must_equal "example.org"
req.hostname.must_equal "example.org"

req = make_request \
Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost:81", "HTTP_X_FORWARDED_HOST" => "somehost:9292, anotherhost:9292, example.org:9292")
req.host.must_equal "example.org"
req.hostname.must_equal "example.org"

req = make_request \
Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost:81", "HTTP_X_FORWARDED_HOST" => "[2001:db8:cafe::17]:47011")
req.host.must_equal "[2001:db8:cafe::17]"
Expand Down