diff --git a/lib/faraday/connection.rb b/lib/faraday/connection.rb index 6318de585..a6c3f1f95 100644 --- a/lib/faraday/connection.rb +++ b/lib/faraday/connection.rb @@ -577,7 +577,7 @@ def proxy_from_env(url) case url when String uri = Utils.URI(url) - uri = URI.parse("#{uri.scheme}://#{uri.hostname}").find_proxy + uri = URI.parse("#{uri.scheme}://#{uri.host}").find_proxy when URI uri = url.find_proxy when nil diff --git a/spec/faraday/connection_spec.rb b/spec/faraday/connection_spec.rb index 5c7e3b60c..50112f9c9 100644 --- a/spec/faraday/connection_spec.rb +++ b/spec/faraday/connection_spec.rb @@ -18,6 +18,13 @@ it { expect(subject.path_prefix).to eq('/fish') } it { expect(subject.params).to eq('a' => '1') } end + + context 'with IPv6 address' do + let(:address) { 'http://[::1]:85/' } + + it { expect(subject.host).to eq('[::1]') } + it { expect(subject.port).to eq(85) } + end end shared_examples 'default connection options' do