Skip to content

Commit 22b2e7f

Browse files
committed
Keep brackets around IPv6 addresses in Endpoint#authority
1 parent b6bf5b6 commit 22b2e7f

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎lib/async/http/endpoint.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ def scheme
158158
# @returns [String] The authority component (hostname and optional port).
159159
def authority(ignore_default_port = true)
160160
if ignore_default_port and default_port?
161-
@url.hostname
161+
@url.host
162162
else
163-
"#{@url.hostname}:#{port}"
163+
"#{@url.host}:#{port}"
164164
end
165165
end
166166

‎test/async/http/endpoint.rb‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@
5757
end
5858
end
5959

60+
with "#authority" do
61+
it "keeps brackets around an IPv6 address" do
62+
expect(Async::HTTP::Endpoint.parse("http://[::1]:8080")).to have_attributes(authority: be == "[::1]:8080")
63+
expect(Async::HTTP::Endpoint.parse("http://[::1]")).to have_attributes(authority: be == "[::1]")
64+
end
65+
66+
it "leaves hostnames and IPv4 addresses unchanged" do
67+
expect(Async::HTTP::Endpoint.parse("http://localhost:8080")).to have_attributes(authority: be == "localhost:8080")
68+
expect(Async::HTTP::Endpoint.parse("http://127.0.0.1")).to have_attributes(authority: be == "127.0.0.1")
69+
end
70+
end
71+
6072
with "#tls_configuration" do
6173
let(:tls_configuration) do
6274
IO::Endpoint::TLS::Configuration.new(verification: :none)

0 commit comments

Comments
 (0)