From fa84a9256f64a7cb67a174e4d53f6684dfcf5942 Mon Sep 17 00:00:00 2001 From: Andrew Fader Date: Thu, 22 Oct 2026 01:57:13 -0400 Subject: [PATCH] Keep brackets around IPv6 addresses in Endpoint#authority Signed-off-by: Andrew Fader --- lib/async/http/endpoint.rb | 4 ++-- test/async/http/endpoint.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/async/http/endpoint.rb b/lib/async/http/endpoint.rb index 469d3fe8..ecccc601 100644 --- a/lib/async/http/endpoint.rb +++ b/lib/async/http/endpoint.rb @@ -158,9 +158,9 @@ def scheme # @returns [String] The authority component (hostname and optional port). def authority(ignore_default_port = true) if ignore_default_port and default_port? - @url.hostname + @url.host else - "#{@url.hostname}:#{port}" + "#{@url.host}:#{port}" end end diff --git a/test/async/http/endpoint.rb b/test/async/http/endpoint.rb index f038fcfe..be078f1c 100644 --- a/test/async/http/endpoint.rb +++ b/test/async/http/endpoint.rb @@ -57,6 +57,18 @@ end end + with "#authority" do + it "keeps brackets around an IPv6 address" do + expect(Async::HTTP::Endpoint.parse("http://[::1]:8080")).to have_attributes(authority: be == "[::1]:8080") + expect(Async::HTTP::Endpoint.parse("http://[::1]")).to have_attributes(authority: be == "[::1]") + end + + it "leaves hostnames and IPv4 addresses unchanged" do + expect(Async::HTTP::Endpoint.parse("http://localhost:8080")).to have_attributes(authority: be == "localhost:8080") + expect(Async::HTTP::Endpoint.parse("http://127.0.0.1")).to have_attributes(authority: be == "127.0.0.1") + end + end + with "#tls_configuration" do let(:tls_configuration) do IO::Endpoint::TLS::Configuration.new(verification: :none)