Follow redirects when connecting to server

This commit is contained in:
Matt 2020-03-21 12:42:25 -04:00
parent 69bb8bca04
commit 0647447c3c
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):
response = self.send_request(server_address, "system/info/public")
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)
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)
server = {
'address': address,
}
self._update_server_info(server, public_info)
server = self.connect_to_server(server, options)
if server is False:
LOG.error("connectToAddress %s failed", address)
@ -164,6 +165,7 @@ class ConnectionManager(object):
LOG.info("calling onSuccessfulConnection with server %s", server.get('Name'))
self._update_server_info(server, result)
credentials = self.credentials.get()
return self._after_connect_validated(server, credentials, result, True, options)