Commit 3ed1d3e7 authored by inso's avatar inso

Add proxy to connection handlers

parent 70f4bc28
......@@ -43,7 +43,7 @@ ERROR_SCHEMA = {
class ConnectionHandler(object):
"""Helper class used by other API classes to ease passing server connection information."""
def __init__(self, http_scheme, ws_scheme, server, port, session=None):
def __init__(self, http_scheme, ws_scheme, server, port, proxy=None, session=None):
"""
Init instance of connection handler
......@@ -54,6 +54,7 @@ class ConnectionHandler(object):
self.http_scheme = http_scheme
self.ws_scheme = ws_scheme
self.server = server
self.proxy = proxy
self.port = port
self.session = session
......@@ -152,7 +153,8 @@ class API(object):
logging.debug("Request : {0}".format(self.reverse_url(self.connection_handler.http_scheme, path)))
with aiohttp.Timeout(15):
url = self.reverse_url(self.connection_handler.http_scheme, path)
response = await self.connection_handler.session.get(url, params=kwargs,headers=self.headers)
response = await self.connection_handler.session.get(url, params=kwargs, headers=self.headers,
proxy=self.connection_handler.proxy)
if response.status != 200:
try:
error_data = parse_error(await response.text())
......@@ -177,7 +179,8 @@ class API(object):
response = await self.connection_handler.session.post(
self.reverse_url(self.connection_handler.http_scheme, path),
data=kwargs,
headers=self.headers
headers=self.headers,
proxy=self.connection_handler.proxy
)
return response
......@@ -189,4 +192,4 @@ class API(object):
:rtype: aiohttp.ClientWebSocketResponse
"""
url = self.reverse_url(self.connection_handler.ws_scheme, path)
return self.connection_handler.session.ws_connect(url)
return self.connection_handler.session.ws_connect(url, proxy=self.connection_handler.proxy)
......@@ -180,7 +180,7 @@ class BMAEndpoint(Endpoint):
IPv6=(" {0}".format(self.ipv6) if self.ipv6 else ""),
PORT=(" {0}".format(self.port) if self.port else ""))
def conn_handler(self, session=None):
def conn_handler(self, session=None, proxy=None):
"""
Return connection handler instance for the endpoint
......@@ -188,11 +188,11 @@ class BMAEndpoint(Endpoint):
:rtype: ConnectionHandler
"""
if self.server:
return ConnectionHandler("http", "ws", self.server, self.port, session)
return ConnectionHandler("http", "ws", self.server, self.port, proxy, session)
elif self.ipv4:
return ConnectionHandler("http", "ws", self.ipv4, self.port, session)
return ConnectionHandler("http", "ws", self.ipv4, self.port, proxy, session)
else:
return ConnectionHandler("http", "ws", "[{0}]".format(self.ipv6), self.port, session)
return ConnectionHandler("http", "ws", "[{0}]".format(self.ipv6), self.port, proxy, session)
def __str__(self):
return self.inline()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment