Properly handle older HTTPSConnection. Fixes #513

This commit is contained in:
Matt Martz 2018-05-22 15:28:00 -05:00
parent 9c2977acfc
commit 9e185e8f88
1 changed files with 12 additions and 4 deletions

View File

@ -389,13 +389,11 @@ class SpeedtestHTTPConnection(HTTPConnection):
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
source_address = kwargs.pop('source_address', None) source_address = kwargs.pop('source_address', None)
context = kwargs.pop('context', None)
timeout = kwargs.pop('timeout', 10) timeout = kwargs.pop('timeout', 10)
HTTPConnection.__init__(self, *args, **kwargs) HTTPConnection.__init__(self, *args, **kwargs)
self.source_address = source_address self.source_address = source_address
self._context = context
self.timeout = timeout self.timeout = timeout
def connect(self): def connect(self):
@ -420,6 +418,17 @@ if HTTPSConnection:
"""Custom HTTPSConnection to support source_address across """Custom HTTPSConnection to support source_address across
Python 2.4 - Python 3 Python 2.4 - Python 3
""" """
def __init__(self, *args, **kwargs):
source_address = kwargs.pop('source_address', None)
context = kwargs.pop('context', None)
timeout = kwargs.pop('timeout', 10)
HTTPSConnection.__init__(self, *args, **kwargs)
self.source_address = source_address
self._context = context
self.timeout = timeout
def connect(self): def connect(self):
"Connect to a host on a given (SSL) port." "Connect to a host on a given (SSL) port."
@ -428,7 +437,6 @@ if HTTPSConnection:
kwargs = {} kwargs = {}
if hasattr(ssl, 'SSLContext'): if hasattr(ssl, 'SSLContext'):
kwargs['server_hostname'] = self.host kwargs['server_hostname'] = self.host
self.sock = self._context.wrap_socket(self.sock, **kwargs) self.sock = self._context.wrap_socket(self.sock, **kwargs)