Skip to content

Commit

Permalink
Fixed AttributeError 'drain' for server websocket handler #1613
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Kim committed Feb 9, 2017
1 parent e166caf commit 4c92a46
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGES
=======

1.3.1 (2017-02-09)
------------------

- Fixed AttributeError 'drain' for server websocket handler #1613


1.3.0 (2017-02-08)
------------------

Expand Down
5 changes: 5 additions & 0 deletions aiohttp/web_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ def transport(self):
"""Transport used for request processing."""
return self._transport

@property
def transport_pair(self):
"""Reader and writer used for request processing."""
return (self._reader, self._writer)

@reify
def cookies(self):
"""Return request cookies.
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def prepare(self, request):
def _pre_start(self, request):
try:
status, headers, parser, writer, protocol = do_handshake(
request.method, request.headers, request.transport,
request.method, request.headers, request.transport_pair[1],
self._protocols)
except HttpProcessingError as err:
if err.code == 405:
Expand Down
29 changes: 29 additions & 0 deletions tests/test_web_websocket_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,35 @@ def handler(request):
assert data['test'] == expected_value


@asyncio.coroutine
def test_websocket_send_drain(loop, test_client):
@asyncio.coroutine
def handler(request):
ws = web.WebSocketResponse()
yield from ws.prepare(request)

ws._writer._limit = 1

data = yield from ws.receive_json()
drain = ws.send_json(data)
assert drain

yield from drain
yield from ws.close()
return ws

app = web.Application(loop=loop)
app.router.add_route('GET', '/', handler)
client = yield from test_client(app)

ws = yield from client.ws_connect('/')
expected_value = 'value'
ws.send_json({'test': expected_value})

data = yield from ws.receive_json()
assert data['test'] == expected_value


@asyncio.coroutine
def test_websocket_receive_json(loop, test_client):
@asyncio.coroutine
Expand Down

0 comments on commit 4c92a46

Please sign in to comment.