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

Surround IPv6 address in Host header with brackets #388

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/httpclient/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ def set_request_header
if @http_version >= '1.1' and get('Host').empty?
if @request_uri.port == @request_uri.default_port
# GFE/1.3 dislikes default port number (returns 404)
set('Host', "#{@request_uri.hostname}")
set('Host', "#{@request_uri.host}")
else
set('Host', "#{@request_uri.hostname}:#{@request_uri.port}")
set('Host', "#{@request_uri.host}:#{@request_uri.port}")
end
end
end
Expand Down
10 changes: 9 additions & 1 deletion test/test_httpclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,15 @@ def test_ipv6literaladdress_in_uri
}
uri = "http://[::1]:#{server.addr[1]}/"
begin
assert_equal('12345', @client.get(uri).body)
str = ""
@client.debug_dev = str
res = @client.get(uri)
assert_equal('12345', res.body)
lines = str.split(/(?:\r?\n)+/)
assert_equal("= Request", lines[0])
assert_equal("! CONNECTION ESTABLISHED", lines[2])
assert_equal("GET / HTTP/1.1", lines[3])
assert_equal("Host: [::1]:#{server.addr[1]}", lines[7])
ensure
server.close
server_thread.kill
Expand Down