Skip to content

Commit

Permalink
Resolve only AF_INET family, because it is not clear how to pass extr…
Browse files Browse the repository at this point in the history
…a info to asyncio
  • Loading branch information
fafhrd91 committed Nov 15, 2013
1 parent 7cbe269 commit 1a2fc42
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
@@ -1,6 +1,12 @@
CHANGES
=======

0.4.4 (11-15-2013)
------------------

- Resolve only AF_INET family, because it is not clear how to pass extra info to asyncio.


0.4.3 (11-15-2013)
------------------

Expand Down
13 changes: 8 additions & 5 deletions aiohttp/client.py
Expand Up @@ -114,8 +114,10 @@ def request(method, url, *,
transport, proto, req, wrp, timeout, loop)
except asyncio.TimeoutError:
raise aiohttp.TimeoutError from None
except aiohttp.BadStatusLine as exc:
raise aiohttp.ClientConnectionError(exc)
except OSError as exc:
raise aiohttp.ConnectionError(exc)
raise aiohttp.OsConnectionError(exc)
finally:
conn_task.cancel()

Expand Down Expand Up @@ -253,12 +255,12 @@ def _resolve_host(self, host, port):
key = (host, port)
if key not in self._resolved_hosts:
infos = yield from self._loop.getaddrinfo(
host, port, type=socket.SOCK_STREAM)
host, port, type=socket.SOCK_STREAM, family=socket.AF_INET)

hosts = []
for family, _, proto, _, address in infos:
hosts.append(
{'host': host, 'port': port,
{'host': address[0], 'port': address[1],
'ssl': self._ssl, 'family': family,
'proto': proto, 'flags': socket.AI_NUMERICHOST})
self._resolved_hosts[key] = hosts
Expand Down Expand Up @@ -338,8 +340,7 @@ def request(self, method=None, path=None, *,
verify_ssl=verify_ssl, expect100=expect100,
session=self._session, connection_params=conn_params,
loop=self._loop)
except (aiohttp.ConnectionError,
aiohttp.TimeoutError, aiohttp.BadStatusLine):
except (aiohttp.ConnectionError, aiohttp.TimeoutError):
pass
else:
return resp
Expand Down Expand Up @@ -793,6 +794,8 @@ def __repr__(self):
print(super().__str__(), file=out)
return out.getvalue()

__str__ = __repr__

def start(self, stream, transport):
"""Start response processing."""
self.stream = stream
Expand Down
11 changes: 10 additions & 1 deletion aiohttp/errors.py
Expand Up @@ -2,7 +2,8 @@

__all__ = ['HttpException', 'HttpErrorException', 'BadRequestException',
'IncompleteRead', 'BadStatusLine', 'LineTooLong', 'InvalidHeader',
'ConnectionError', 'TimeoutError']
'ConnectionError', 'OsConnectionError', 'ClientConnectionError',
'TimeoutError']

import http.client
from asyncio import TimeoutError
Expand All @@ -12,6 +13,14 @@ class ConnectionError(Exception):
"""http connection error"""


class OsConnectionError(ConnectionError):
"""OSError error"""


class ClientConnectionError(ConnectionError):
"""BadStatusLine error """


class HttpException(http.client.HTTPException):

code = None
Expand Down
2 changes: 1 addition & 1 deletion setup.py
@@ -1,7 +1,7 @@
import os
from setuptools import setup, find_packages

version = '0.4.3'
version = '0.4.4'

install_requires = ['asyncio']
tests_require = install_requires + ['nose', 'gunicorn']
Expand Down
2 changes: 1 addition & 1 deletion tests/http_client_functional_test.py
Expand Up @@ -534,7 +534,7 @@ def test_request_conn_closed(self):
with test_utils.run_server(self.loop, router=Functional) as httpd:
httpd['close'] = True
self.assertRaises(
aiohttp.HttpException,
aiohttp.ClientConnectionError,
self.loop.run_until_complete,
client.request('get', httpd.url('method', 'get'),
loop=self.loop))
Expand Down

0 comments on commit 1a2fc42

Please sign in to comment.