From 5b0065cf3a20f2483aa0a80c8029899fb1b7a6e6 Mon Sep 17 00:00:00 2001 From: Inso Date: Thu, 17 Sep 2015 19:11:43 +0200 Subject: [PATCH] Fix host detection raising unclear exception --- aiohttp/client_reqrep.py | 3 +++ tests/test_client_request.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/aiohttp/client_reqrep.py b/aiohttp/client_reqrep.py index f0e42618b4b..d9de6798a5d 100644 --- a/aiohttp/client_reqrep.py +++ b/aiohttp/client_reqrep.py @@ -112,6 +112,9 @@ def update_host(self, url): # get host/port host = url_parsed.hostname + if not host: + raise ValueError('Host could not be detected.') + try: port = url_parsed.port except ValueError: diff --git a/tests/test_client_request.py b/tests/test_client_request.py index 912d9563647..155b23a5e3b 100644 --- a/tests/test_client_request.py +++ b/tests/test_client_request.py @@ -96,6 +96,11 @@ def test_host_port_err(self): ValueError, ClientRequest, 'get', 'http://python.org:123e/', loop=self.loop) + def test_hostname_err(self): + self.assertRaises( + ValueError, ClientRequest, 'get', 'http://:8080/', + loop=self.loop) + def test_host_header(self): req = ClientRequest('get', 'http://python.org/', loop=self.loop) self.assertEqual(req.headers['HOST'], 'python.org')