Skip to content

Commit bdc4bc2

Browse files
committed
Keep brackets around IPv6 addresses in Endpoint#authority
Signed-off-by: Andrew Fader <fader@yagni.co>
1 parent b6bf5b6 commit bdc4bc2

2 files changed

Lines changed: 18 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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@
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 "keeps brackets around an IPv6 address when including the default port" do
67+
expect(Async::HTTP::Endpoint.parse("http://[::1]").authority(false)).to be == "[::1]:80"
68+
end
69+
70+
it "leaves hostnames and IPv4 addresses unchanged" do
71+
expect(Async::HTTP::Endpoint.parse("http://localhost:8080")).to have_attributes(authority: be == "localhost:8080")
72+
expect(Async::HTTP::Endpoint.parse("http://127.0.0.1")).to have_attributes(authority: be == "127.0.0.1")
73+
end
74+
end
75+
6076
with "#tls_configuration" do
6177
let(:tls_configuration) do
6278
IO::Endpoint::TLS::Configuration.new(verification: :none)

0 commit comments

Comments
 (0)