summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ceilometerclient/common/http.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/ceilometerclient/common/http.py b/ceilometerclient/common/http.py
index 1c6f29b..a02c881 100644
--- a/ceilometerclient/common/http.py
+++ b/ceilometerclient/common/http.py
@@ -47,6 +47,7 @@ class HTTPClient(object):
self.endpoint = endpoint
self.auth_token = kwargs.get('token')
self.connection_params = self.get_connection_params(endpoint, **kwargs)
+ self.proxy_url = self.get_proxy_url()
@staticmethod
def get_connection_params(endpoint, **kwargs):
@@ -73,8 +74,13 @@ class HTTPClient(object):
def get_connection(self):
_class = self.connection_params[0]
try:
- return _class(*self.connection_params[1][0:2],
- **self.connection_params[2])
+ if self.proxy_url:
+ proxy_parts = urlutils.urlparse(self.proxy_url)
+ return _class(proxy_parts.hostname, proxy_parts.port,
+ **self.connection_params[2])
+ else:
+ return _class(*self.connection_params[1][0:2],
+ **self.connection_params[2])
except httplib.InvalidURL:
raise exc.InvalidEndpoint()
@@ -136,7 +142,10 @@ class HTTPClient(object):
conn = self.get_connection()
try:
- conn_url = self._make_connection_url(url)
+ if self.proxy_url:
+ conn_url = self.endpoint + self._make_connection_url(url)
+ else:
+ conn_url = self._make_connection_url(url)
conn.request(method, conn_url, **kwargs)
resp = conn.getresponse()
except socket.gaierror as e:
@@ -201,6 +210,15 @@ class HTTPClient(object):
'application/octet-stream')
return self._http_request(url, method, **kwargs)
+ def get_proxy_url(self):
+ scheme = urlutils.urlparse(self.endpoint).scheme
+ if scheme == 'https':
+ return os.environ.get('https_proxy')
+ elif scheme == 'http':
+ return os.environ.get('http_proxy')
+ msg = 'Unsupported scheme: %s' % scheme
+ raise exc.InvalidEndpoint(msg)
+
class VerifiedHTTPSConnection(httplib.HTTPSConnection):
"""httplib-compatibile connection using client-side SSL authentication