Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support IPv6 addresses in the :net_http adapter #621

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/faraday/adapter/net_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/adapters/excon_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
2 changes: 1 addition & 1 deletion test/adapters/httpclient_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
13 changes: 11 additions & 2 deletions test/adapters/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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] ||= {}
Expand Down
12 changes: 11 additions & 1 deletion test/adapters/net_http_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class NetHttpTest < Faraday::TestCase

def adapter() :net_http end

behaviors = [:NonParallel, :Compression]
behaviors = [:NonParallel, :Compression, :IPv6]

Integration.apply(self, *behaviors)

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/adapters/patron_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/adapters/typhoeus_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down