diff --git a/matrix/server.py b/matrix/server.py index b26672c..040b9ef 100644 --- a/matrix/server.py +++ b/matrix/server.py @@ -325,7 +325,7 @@ class MatrixServer(object): device_file.write(self.device_id) @staticmethod - def _parse_url(address, port): + def _parse_url(address): parsed_url = urlparse(address) if parsed_url.netloc: @@ -336,24 +336,18 @@ class MatrixServer(object): except ValueError: netloc, path = (address, "") - path = path.strip("/") - - return netloc, "/".join([ - "{}:{}".format(netloc, port), - path - ]).rstrip("/") + return netloc, path.strip("/") def _change_client(self): - netloc, host = MatrixServer._parse_url( - self.config.address, - str(self.config.port) - ) + netloc, extra_path = MatrixServer._parse_url(self.config.address) + host = "{}:{}".format(netloc, self.config.port) self.address = netloc self.client = HttpClient( host, self.config.username, self.device_id, - self.get_session_path() + self.get_session_path(), + extra_path=extra_path ) def update_option(self, option, option_name): diff --git a/tests/server_test.py b/tests/server_test.py index 7b0513c..764c19a 100644 --- a/tests/server_test.py +++ b/tests/server_test.py @@ -6,21 +6,20 @@ G.CONFIG = MockConfig() class TestClass(object): def test_address_parsing(self): - netloc, host = MatrixServer._parse_url("example.org", "443") - assert host == "example.org:443" - assert netloc == "example.org" + host, extra_path = MatrixServer._parse_url("example.org") + assert host == "example.org" + assert extra_path == "" - netloc, host = MatrixServer._parse_url("example.org/_matrix", "443") - assert host == "example.org:443/_matrix" - assert netloc == "example.org" + host, extra_path = MatrixServer._parse_url("example.org/_matrix") + assert host == "example.org" + assert extra_path == "_matrix" - netloc, host = MatrixServer._parse_url( - "https://example.org/_matrix", - "443" + host, extra_path = MatrixServer._parse_url( + "https://example.org/_matrix" ) - assert host == "example.org:443/_matrix" - assert netloc == "example.org" + assert host == "example.org" + assert extra_path == "_matrix" - netloc, host = MatrixServer._parse_url("https://example.org", "443") - assert host == "example.org:443" - assert netloc == "example.org" + host, extra_path = MatrixServer._parse_url("https://example.org") + assert host == "example.org" + assert extra_path == ""