Permalink
Browse files

Work around httplib2 tunnelling bug

Fixes bug #1051007

httplib2 defaults to using HTTP CONNECT tunnelling even for plain HTTP
connections. This is problematic with proxies configured to only allow
tunnelling to port 443. This is the default configuration for squid.

Hack around the problem by forcing httplib2 to use the HTTP_NO_TUNNEL
proxy type which disables tunnelling except for port 443.

Change-Id: I59cd95ed74a9bb795779fc38fbc0935266cc8b22
  • Loading branch information...
1 parent eb20c5a commit aaa38ce0e54d97d744826e0b353ec79329cbaf91 @markmc markmc committed Sep 14, 2012
Showing with 33 additions and 1 deletion.
  1. +33 −1 novaclient/client.py
View
@@ -46,6 +46,37 @@ def get_auth_system_url(auth_system):
raise exceptions.AuthSystemNotFound(auth_system)
+def _get_proxy_info():
+ """Work around httplib2 proxying bug.
+
+ Full details of the bug here:
+
+ http://code.google.com/p/httplib2/issues/detail?id=228
+
+ Basically, in the case of plain old http with httplib2>=0.7.5 we
+ want to ensure that PROXY_TYPE_HTTP_NO_TUNNEL is used.
+ """
+ def get_proxy_info(method):
+ pi = httplib2.ProxyInfo.from_environment(method)
+ if pi is None or method != 'http':
+ return pi
+
+ # We can't rely on httplib2.socks being available
+ # PROXY_TYPE_HTTP_NO_TUNNEL was introduced in 0.7.5
+ if not (hasattr(httplib2, 'socks') and
+ hasattr(httplib2.socks, 'PROXY_TYPE_HTTP_NO_TUNNEL')):
+ return pi
+
+ pi.proxy_type = httplib2.socks.PROXY_TYPE_HTTP_NO_TUNNEL
+ return pi
+
+ # 0.7.3 introduced configuring proxy from the environment
+ if not hasattr(httplib2.ProxyInfo, 'from_environment'):
+ return None
+
+ return get_proxy_info
+
+
class HTTPClient(httplib2.Http):
USER_AGENT = 'python-novaclient'
@@ -57,7 +88,8 @@ def __init__(self, user, password, projectid, auth_url=None,
service_name=None, volume_service_name=None,
timings=False, bypass_url=None, no_cache=False,
http_log_debug=False, auth_system='keystone'):
- super(HTTPClient, self).__init__(timeout=timeout)
+ super(HTTPClient, self).__init__(timeout=timeout,
+ proxy_info=_get_proxy_info())
self.user = user
self.password = password
self.projectid = projectid

0 comments on commit aaa38ce

Please sign in to comment.