diff --git a/aiohttp/client_reqrep.py b/aiohttp/client_reqrep.py index 9b235c62604..53cdede61c4 100644 --- a/aiohttp/client_reqrep.py +++ b/aiohttp/client_reqrep.py @@ -129,7 +129,7 @@ def update_host(self, url): self.netloc = netloc scheme = url_parsed.scheme - self.ssl = scheme == 'https' + self.ssl = scheme in ('https', 'wss') # set port number if it isn't already set if not port: @@ -175,7 +175,7 @@ def update_path(self, params): query = params self.path = urllib.parse.urlunsplit( - ('', '', urllib.parse.quote(path, safe='/%:'), query, fragment)) + ('', '', urllib.parse.quote(path, safe='/%:='), query, fragment)) self.url = urllib.parse.urlunsplit( (scheme, netloc, self.path, '', '')) diff --git a/tests/test_client_request.py b/tests/test_client_request.py index ca88def9701..f7971903707 100644 --- a/tests/test_client_request.py +++ b/tests/test_client_request.py @@ -73,6 +73,19 @@ def test_host_port(self): self.assertTrue(req.ssl) self.loop.run_until_complete(req.close()) + def test_websocket_host_port(self): + req = ClientRequest('get', 'ws://python.org/', loop=self.loop) + self.assertEqual(req.host, 'python.org') + self.assertEqual(req.port, 80) + self.assertFalse(req.ssl) + self.loop.run_until_complete(req.close()) + + req = ClientRequest('get', 'wss://python.org/', loop=self.loop) + self.assertEqual(req.host, 'python.org') + self.assertEqual(req.port, 443) + self.assertTrue(req.ssl) + self.loop.run_until_complete(req.close()) + def test_host_port_err(self): self.assertRaises( ValueError, ClientRequest, 'get', 'http://python.org:123e/', @@ -230,6 +243,12 @@ def test_path_is_not_double_encoded(self): self.assertEqual(req.path, "/get/test%20case") self.loop.run_until_complete(req.close()) + def test_path_safe_chars_preserved(self): + req = ClientRequest('get', "http://0.0.0.0/get/%:=", + loop=self.loop) + self.assertEqual(req.path, "/get/%:=") + self.loop.run_until_complete(req.close()) + def test_params_are_added_before_fragment(self): req = ClientRequest( 'GET', "http://example.com/path#fragment", params={"a": "b"},