Updated address normalization to test for https first to fix #223

This commit is contained in:
Abby Gourlay 2020-03-18 02:38:08 +00:00
commit 014ee602ef

View file

@ -283,21 +283,22 @@ class ConnectionManager(object):
return None return None
def _normalize_address(self, address): def _normalize_address(self, address):
# TODO: Try HTTPS first, then HTTP if that fails.
if '://' not in address:
address = 'http://' + address
# Attempt to correct bad input # Attempt to correct bad input
url = urllib3.util.parse_url(address.strip()) url = urllib3.util.parse_url(address.strip())
if url.scheme is None: # Default to using https
url = url._replace(scheme='http') url = url._replace(scheme='https')
if url.scheme == 'http' and url.port == 80: # Test if server is reachable over https
url = url._replace(port=None) if self.API.get_public_info(url):
if url.scheme == 'https' and url.port == 443:
if url.scheme == 'https' and url.port == 443: url = url._replace(port=None)
url = url._replace(port=None) else:
# Server didn't give an expected response over https
# Try http instead
url._replace(scheme='http')
if url.scheme == 'http' and url.port == 80:
url = url._replace(port=None)
return url.url return url.url