Skip to content

Commit

Permalink
ProxyConnector doesn't support keep-alive requests by default startin…
Browse files Browse the repository at this point in the history
…g from now #368

Add connector.force_close property
  • Loading branch information
asvetlov committed May 18, 2015
1 parent d448990 commit 792b980
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ CHANGES

- Add `response_class` parameter to `ws_connect()` #367

- `ProxyConnector` doesn't support keep-alive requests by default
starting from now #368

- Add `connector.force_close` property


0.15.3 (04-22-2015)
-------------------
Expand Down
10 changes: 8 additions & 2 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ def __del__(self):
context['source_traceback'] = self._source_traceback
self._loop.call_exception_handler(context)

@property
def force_close(self):
"""Ultimately close connection on releasing."""
return self._force_close

def _cleanup(self):
"""Cleanup unused transports."""
if self._cleanup_handle:
Expand Down Expand Up @@ -493,8 +498,9 @@ class ProxyConnector(TCPConnector):
"""

def __init__(self, proxy, *, proxy_auth=None, **kwargs):
super().__init__(**kwargs)
def __init__(self, proxy, *, proxy_auth=None, force_close=True,
**kwargs):
super().__init__(force_close=force_close, **kwargs)
self._proxy = proxy
self._proxy_auth = proxy_auth
assert proxy.startswith('http://'), (
Expand Down
5 changes: 5 additions & 0 deletions docs/client_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ All connector classes should be derived from :class:`BaseConnector`.

Read-only property, ``True`` if connector is closed.

.. attribute:: force_close

Read-only property, ``True`` if connector should ultimately
close connections on releasing.

.. method:: close()

Close all opened connections.
Expand Down
5 changes: 5 additions & 0 deletions tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,10 @@ class Req:

self.loop.run_until_complete(go())

def test_default_force_close(self):
connector = aiohttp.BaseConnector(loop=self.loop)
self.assertFalse(connector.force_close)


class TestHttpClientConnector(unittest.TestCase):

Expand Down Expand Up @@ -718,6 +722,7 @@ def test_ctor2(self):
loop=self.loop)

self.assertEqual('http://localhost:8118', connector.proxy)
self.assertTrue(connector.force_close)

@unittest.mock.patch('aiohttp.connector.ClientRequest')
def test_connect(self, ClientRequestMock):
Expand Down

0 comments on commit 792b980

Please sign in to comment.