diff --git a/lib/faraday/adapter/net_http.rb b/lib/faraday/adapter/net_http.rb index 28b85a5a9..14cba07be 100644 --- a/lib/faraday/adapter/net_http.rb +++ b/lib/faraday/adapter/net_http.rb @@ -89,10 +89,10 @@ def with_net_http_connection(env) def net_http_connection(env) if proxy = env[:request][:proxy] - Net::HTTP::Proxy(proxy[:uri].host, proxy[:uri].port, proxy[:user], proxy[:password]) + Net::HTTP::Proxy(proxy[:uri].hostname, proxy[:uri].port, proxy[:user], proxy[:password]) else Net::HTTP - end.new(env[:url].host, env[:url].port || (env[:url].scheme == 'https' ? 443 : 80)) + end.new(env[:url].hostname, env[:url].port || (env[:url].scheme == 'https' ? 443 : 80)) end def configure_ssl(http, ssl) diff --git a/test/adapters/excon_test.rb b/test/adapters/excon_test.rb index f7b99675f..bf388d4e7 100644 --- a/test/adapters/excon_test.rb +++ b/test/adapters/excon_test.rb @@ -5,7 +5,7 @@ class ExconTest < Faraday::TestCase def adapter() :excon end - Integration.apply(self, :NonParallel) do + Integration.apply(self, :NonParallel, :IPv6) do # https://github.com/geemus/excon/issues/126 ? undef :test_timeout if ssl_mode? diff --git a/test/adapters/httpclient_test.rb b/test/adapters/httpclient_test.rb index 41a5f2f18..052e9b967 100644 --- a/test/adapters/httpclient_test.rb +++ b/test/adapters/httpclient_test.rb @@ -5,7 +5,7 @@ class HttpclientTest < Faraday::TestCase def adapter() :httpclient end - Integration.apply(self, :NonParallel, :Compression) do + Integration.apply(self, :NonParallel, :Compression, :IPv6) do def setup require 'httpclient' unless defined?(HTTPClient) HTTPClient::NO_PROXY_HOSTS.delete('localhost') diff --git a/test/adapters/integration.rb b/test/adapters/integration.rb index a5a57c957..9738b28b8 100644 --- a/test/adapters/integration.rb +++ b/test/adapters/integration.rb @@ -75,6 +75,16 @@ def test_GET_ssl_fails_with_bad_cert end end + module IPv6 + def test_simple_ipv6_request + server = self.class.live_server + uri = URI('%s://%s:%d' % [server.scheme, '[::1]', server.port]) + conn = create_connection({}, uri) + + assert_equal 'get', conn.get('echo').body + end + end + module Common extend Forwardable def_delegators :create_connection, :get, :head, :put, :post, :patch, :delete, :run_request @@ -234,7 +244,7 @@ def adapter_options [] end - def create_connection(options = {}) + def create_connection(options = {}, server = self.class.live_server) if adapter == :default builder_block = nil else @@ -245,7 +255,6 @@ def create_connection(options = {}) end end - server = self.class.live_server url = '%s://%s:%d' % [server.scheme, server.host, server.port] options[:ssl] ||= {} diff --git a/test/adapters/net_http_test.rb b/test/adapters/net_http_test.rb index 296300563..8a109c359 100644 --- a/test/adapters/net_http_test.rb +++ b/test/adapters/net_http_test.rb @@ -7,7 +7,7 @@ class NetHttpTest < Faraday::TestCase def adapter() :net_http end - behaviors = [:NonParallel, :Compression] + behaviors = [:NonParallel, :Compression, :IPv6] Integration.apply(self, *behaviors) @@ -40,5 +40,15 @@ def test_explicit_port_number assert_equal 1234, http.port end + def test_ipv6_uri + url = URI('http://[::1]') + url.port = nil + + adapter = Faraday::Adapter::NetHttp.new + http = adapter.net_http_connection(:url => url, :request => {}) + + assert_equal '::1', http.address + end + end end diff --git a/test/adapters/patron_test.rb b/test/adapters/patron_test.rb index dfec0517e..df1645b16 100644 --- a/test/adapters/patron_test.rb +++ b/test/adapters/patron_test.rb @@ -6,7 +6,7 @@ class Patron < Faraday::TestCase def adapter() :patron end unless jruby? - Integration.apply(self, :NonParallel) do + Integration.apply(self, :NonParallel, :IPv6) do # https://github.com/toland/patron/issues/34 undef :test_PATCH_send_url_encoded_params diff --git a/test/adapters/typhoeus_test.rb b/test/adapters/typhoeus_test.rb index bc4ec33e7..e2f163990 100644 --- a/test/adapters/typhoeus_test.rb +++ b/test/adapters/typhoeus_test.rb @@ -5,7 +5,7 @@ class TyphoeusTest < Faraday::TestCase def adapter() :typhoeus end - Integration.apply(self, :Parallel) do + Integration.apply(self, :Parallel, :IPv6) do # https://github.com/dbalatero/typhoeus/issues/75 undef :test_GET_with_body