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

Prefer #hostname over #host. #714

Merged
merged 1 commit into from
Jul 26, 2017
Merged

Conversation

bdunne
Copy link
Contributor

@bdunne bdunne commented Jul 24, 2017

#hostname will remove brackets on IPv6 addresses. Since [::1] is not resolvable, using #host is causing all IPv6 addresses to fail.

Before the change...

irb(main):008:0> u2 = URI.parse("https://[::1]:443/x/y/z")
=> #<URI::HTTPS https://[::1]/x/y/z>
irb(main):009:0> u2.host
=> "[::1]"
irb(main):010:0> u2.hostname
=> "::1"
irb(main):011:0> require 'faraday'
=> true
irb(main):012:0> c = Faraday.new("http://[::1]:3000") { |f| f.adapter(Faraday.default_adapter) }
=> #<Faraday::Connection:0x00000000f38248 @parallel_manager=nil, @headers={"User-Agent"=>"Faraday v0.12.0.1"}, @params={}, @options=#<Faraday::RequestOptions (empty)>, @ssl=#<Faraday::SSLOptions (empty)>, @default_parallel_manager=nil, @builder=#<Faraday::RackBuilder:0x00000000f27f10 @handlers=[Faraday::Adapter::NetHttp]>, @url_prefix=#<URI::HTTP http://[::1]:3000/>, @proxy=nil>
irb(main):013:0> c.get("/")
Faraday::ConnectionFailed: Failed to open TCP connection to [::1]:3000 (getaddrinfo: Name or service not known)
	from /home/bdunne/.rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:882:in `rescue in block in connect'
	from /home/bdunne/.rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:879:in `block in connect'
	from /home/bdunne/.rubies/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
	from /home/bdunne/.rubies/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
	from /home/bdunne/.rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:878:in `connect'
	from /home/bdunne/.rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
	from /home/bdunne/.rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:852:in `start'
	from /home/bdunne/.rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:1398:in `request'
	from /home/bdunne/.rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:1156:in `get'
	from /home/bdunne/.gem/ruby/2.3.3/gems/faraday-0.12.0.1/lib/faraday/adapter/net_http.rb:78:in `perform_request'
	from /home/bdunne/.gem/ruby/2.3.3/gems/faraday-0.12.0.1/lib/faraday/adapter/net_http.rb:38:in `block in call'
	from /home/bdunne/.gem/ruby/2.3.3/gems/faraday-0.12.0.1/lib/faraday/adapter/net_http.rb:85:in `with_net_http_connection'
	from /home/bdunne/.gem/ruby/2.3.3/gems/faraday-0.12.0.1/lib/faraday/adapter/net_http.rb:33:in `call'
	from /home/bdunne/.gem/ruby/2.3.3/gems/faraday-0.12.0.1/lib/faraday/rack_builder.rb:139:in `build_response'
	from /home/bdunne/.gem/ruby/2.3.3/gems/faraday-0.12.0.1/lib/faraday/connection.rb:386:in `run_request'
	from /home/bdunne/.gem/ruby/2.3.3/gems/faraday-0.12.0.1/lib/faraday/connection.rb:149:in `get'
	from (irb):13
	from /home/bdunne/.rubies/ruby-2.3.3/bin/irb:11:in `<main>'

Based on discussion in #621

`#hostname` will remove brackets on IPv6 addresses.  Since [::1] is not
resolvable, using `#host` is causing all IPv6 addresses to fail.
@bdunne
Copy link
Contributor Author

bdunne commented Jul 24, 2017

@iMacTia @mislav Please review

@iMacTia
Copy link
Member

iMacTia commented Jul 26, 2017

It's the second time I get requested this change in a week.
I understand IPv6 is getting some traction but it's still out of the thoughts of some big players (e.g. Travis) and most of the adapters we support. Full details on #621.
I'm going to merge this as I understand this change will make it working on Net::HTTP, but let's be clear on the fact that Faraday won't support IPv6 properly until MOST of the adapters have been updated to do so. Hence, I won't rush on merging hot fixes related to IPv6 before then.

@iMacTia iMacTia added this to the v0.13.0 milestone Jul 26, 2017
@iMacTia iMacTia merged commit 923f905 into lostisland:master Jul 26, 2017
@bdunne bdunne deleted the prefer_hostname branch July 26, 2017 15:15
bdunne added a commit to bdunne/ansible_tower_client that referenced this pull request Aug 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants