Merge pull request #240 from mcarlton00/follow-redirects

Follow redirects when connecting to server
This commit is contained in:
Abby 2020-03-23 00:29:39 +00:00 committed by GitHub
commit 57582d234f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 13 deletions

View file

@ -431,3 +431,12 @@ class API(object):
def get_public_info(self, server_address): def get_public_info(self, server_address):
response = self.send_request(server_address, "system/info/public") response = self.send_request(server_address, "system/info/public")
return response.json() if response.status_code == 200 else {} return response.json() if response.status_code == 200 else {}
def check_redirect(self, server_address):
''' Checks if the server is redirecting traffic to a new URL and
returns the URL the server prefers to use
'''
response = self.send_request(server_address, "system/info/public")
url = response.url.replace('/system/info/public', '')
return url

View file

@ -133,12 +133,13 @@ class ConnectionManager(object):
address = self._normalize_address(address) address = self._normalize_address(address)
try: try:
public_info = self.API.get_public_info(address) response_url = self.API.check_redirect(address)
if address != response_url:
address = response_url
LOG.info("connectToAddress %s succeeded", address) LOG.info("connectToAddress %s succeeded", address)
server = { server = {
'address': address, 'address': address,
} }
self._update_server_info(server, public_info)
server = self.connect_to_server(server, options) server = self.connect_to_server(server, options)
if server is False: if server is False:
LOG.error("connectToAddress %s failed", address) LOG.error("connectToAddress %s failed", address)
@ -164,6 +165,7 @@ class ConnectionManager(object):
LOG.info("calling onSuccessfulConnection with server %s", server.get('Name')) LOG.info("calling onSuccessfulConnection with server %s", server.get('Name'))
self._update_server_info(server, result)
credentials = self.credentials.get() credentials = self.credentials.get()
return self._after_connect_validated(server, credentials, result, True, options) return self._after_connect_validated(server, credentials, result, True, options)