eshad / httplib2

Automatically exported from code.google.com/p/httplib2
0 stars 0 forks source link

IPv6 + SSL = fail #126

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Use Http::request() to go to an IPv6 SSL URL:

>>> import httplib2
>>> httplib2.Http().request("https://[::1]/", "GET")

What is the expected output? What do you see instead?

Expected: 

If you are running a local https server, you should get the contents back.  
Otherwise, it should fail with a "Connection refused" exception.

Actual:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../lib/python2.6/site-packages/httplib2/__init__.py", line 1068, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File ".../lib/python2.6/site-packages/httplib2/__init__.py", line 872, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File ".../lib/python2.6/site-packages/httplib2/__init__.py", line 841, in _conn_request
    conn.request(method, request_uri, body, headers)
  File ".../lib/python2.6/httplib.py", line 918, in request
    self._send_request(method, url, body, headers)
  File ".../lib/python2.6/httplib.py", line 959, in _send_request
    self.endheaders()
  File ".../lib/python2.6/httplib.py", line 902, in endheaders
    self._send_output()
  File ".../lib/python2.6/httplib.py", line 764, in _send_output
    self.send(msg)
  File ".../lib/python2.6/httplib.py", line 723, in send
    self.connect()
  File ".../lib/python2.6/site-packages/httplib2/__init__.py", line 756, in connect
    sock.connect((self.host, self.port))
  File "<string>", line 1, in connect
socket.gaierror: [Errno -9] Address family for hostname not supported

What version of the product are you using? On what operating system?

On this box, I actually have 0.4.0 installed, but the offending code seems to 
still be present in hg HEAD.

Please provide any additional information below.

The HTTPSConnectionWithTimeout class explicitly makes an AF_INET (i.e. IPv4) 
connection:

> class HTTPSConnectionWithTimeout(httplib.HTTPSConnection):
# [...]
>         "Connect to a host on a given (SSL) port."
>
>        if self.proxy_info and self.proxy_info.isgood():
>            sock = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM)
>            sock.setproxy(*self.proxy_info.astuple())
>        else:
>            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>            sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

The non-SSL case (HTTPConnectionWithTimeout) gets this right: it iterate 
through the list of addresses returned by socket.getaddrinfo() and uses the 
address family for each one.

Original issue reported on code.google.com by mitchbl...@gmail.com on 24 Jan 2011 at 10:33

GoogleCodeExporter commented 9 years ago
Fixed in 158:d49d76ecf899.

Original comment by joe.gregorio@gmail.com on 13 Feb 2011 at 5:00

GoogleCodeExporter commented 9 years ago
Issue 121 has been merged into this issue.

Original comment by joe.gregorio@gmail.com on 13 Feb 2011 at 5:02

GoogleCodeExporter commented 9 years ago
Issue 79 has been merged into this issue.

Original comment by joe.gregorio@gmail.com on 13 Feb 2011 at 5:02

GoogleCodeExporter commented 9 years ago
Issue 122 has been merged into this issue.

Original comment by joe.gregorio@gmail.com on 13 Feb 2011 at 5:02

GoogleCodeExporter commented 9 years ago
Great, I just grabbed the latest code from hg and now my application is happily 
working with IPv6.  Thanks for fixing!

Eagerly awaiting the next real release (0.7.0?)

Original comment by mitchbl...@gmail.com on 14 Feb 2011 at 7:31