ostinelli / net-http2

NetHttp2 is an HTTP/2 client for Ruby.
MIT License
140 stars 31 forks source link

IPv6 support? #32

Closed celsworth closed 1 year ago

celsworth commented 6 years ago

I'm unable to use this library with a host that only has a v6 address:

[11] pry(main)> response = client.call(:get, '/')
SocketError: getaddrinfo: Name or service not known
from /home/celsworth/bigv-brain-cloud/vendor/bundle/ruby/2.3.0/gems/net-http2-0.18.0/lib/net-http2/socket.rb:30:in `getaddrinfo'

And the culprit appears to be:

      family   = ::Socket::AF_INET
      address  = ::Socket.getaddrinfo(uri.host, nil, family).first[3]

An IPv6 lookup is not going to succeed while it's forced to AF_INET. Could we get IPv6 support here, or are there other reasons it's limited to v4?

ostinelli commented 6 years ago

Thank you for your report. There are no other reasons other that until now I did not need it, as net-http2 was mainly born as a spinoff of apnotic.

Would you care for a PR?

celsworth commented 6 years ago

I'll have a go :)

My first attempt at simply switching the AF_INET to AF_INET6 as a test brought a new error:

TypeError: no implicit conversion of nil into String
from /home/celsworth/bigv-brain-cloud/vendor/bundle/ruby/2.3.0/gems/net-http2-0.18.0/lib/net-http2/socket.rb:23:in `connect'

So I'm just poking about at the moment..

Edit: Ok that error looks like some local issue because it works just fine with AF_INET6 and connecting to Google.