server: Change the way the homeserver url is passed to nio.

This commit is contained in:
Damir Jelić 2019-07-02 18:09:36 +02:00
parent e82d7013ec
commit 4c8ee2848b

View file

@ -270,6 +270,7 @@ class MatrixServer(object):
pass pass
self.address = None self.address = None
self.homeserver = None
self.client = None self.client = None
self.access_token = None # type: Optional[str] self.access_token = None # type: Optional[str]
self.next_batch = None # type: Optional[str] self.next_batch = None # type: Optional[str]
@ -349,29 +350,31 @@ class MatrixServer(object):
device_file.write(self.device_id) device_file.write(self.device_id)
@staticmethod @staticmethod
def _parse_url(address): def _parse_url(address, port):
if not address.startswith("http"):
address = "https://{}".format(address)
parsed_url = urlparse(address) parsed_url = urlparse(address)
if parsed_url.netloc: homeserver = parsed_url._replace(
netloc, path = (parsed_url.netloc, parsed_url.path) netloc=parsed_url.hostname + ":{}".format(port)
else: )
try:
netloc, path = address.split("/", 1)
except ValueError:
netloc, path = (address, "")
return netloc, path.strip("/") return homeserver
def _change_client(self): def _change_client(self):
netloc, extra_path = MatrixServer._parse_url(self.config.address) homeserver = MatrixServer._parse_url(
host = "{}:{}".format(netloc, self.config.port) self.config.address,
self.address = netloc self.config.port
)
self.address = homeserver.hostname
self.homeserver = homeserver
self.client = HttpClient( self.client = HttpClient(
host, homeserver.geturl(),
self.config.username, self.config.username,
self.device_id, self.device_id,
self.get_session_path(), self.get_session_path(),
extra_path=extra_path
) )
self.client.add_to_device_callback( self.client.add_to_device_callback(
self.key_verification_cb, self.key_verification_cb,