add proxy support to connection (#46)

This commit is contained in:
Jordi Sesmero
2017-11-28 13:23:55 +03:00
committed by Sergey Petrov
parent bbe8528acf
commit a3244df06d
2 changed files with 7 additions and 6 deletions
+4 -4
View File
@@ -33,21 +33,21 @@ class APNsClient(object):
ALTERNATIVE_PORT = 2197
def __init__(self, credentials, use_sandbox=False, use_alternative_port=False, proto=None, json_encoder=None,
password=None):
password=None, proxy_host=None, proxy_port=None):
if credentials is None or isinstance(credentials, str):
self.__credentials = CertificateCredentials(credentials, password)
else:
self.__credentials = credentials
self._init_connection(use_sandbox, use_alternative_port, proto)
self._init_connection(use_sandbox, use_alternative_port, proto, proxy_host, proxy_port)
self.__json_encoder = json_encoder
self.__max_concurrent_streams = None
self.__previous_server_max_concurrent_streams = None
def _init_connection(self, use_sandbox, use_alternative_port, proto):
def _init_connection(self, use_sandbox, use_alternative_port, proto, proxy_host, proxy_port):
server = self.SANDBOX_SERVER if use_sandbox else self.LIVE_SERVER
port = self.ALTERNATIVE_PORT if use_alternative_port else self.DEFAULT_PORT
self._connection = self.__credentials.create_connection(server, port, proto)
self._connection = self.__credentials.create_connection(server, port, proto, proxy_host, proxy_port)
def send_notification(self, token_hex, notification, topic=None, priority=NotificationPriority.Immediate,
expiration=None, collapse_id=None):
+3 -2
View File
@@ -14,9 +14,10 @@ class Credentials(object):
self.__ssl_context = ssl_context
# Creates a connection with the credentials, if available or necessary.
def create_connection(self, server, port, proto):
def create_connection(self, server, port, proto, proxy_host=None, proxy_port=None):
# self.__ssl_context may be none, and that's fine.
return HTTP20Connection(server, port, ssl_context=self.__ssl_context, force_proto=proto or 'h2')
return HTTP20Connection(server, port, ssl_context=self.__ssl_context, force_proto=proto or 'h2',
proxy_host=proxy_host, proxy_port=proxy_port)
def get_authorization_header(self, topic):
return None