Skip to content

Commit

Permalink
Fixed AttributeError in WebSocketResponse.can_prepare #1736
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Mar 21, 2017
1 parent be81ce7 commit eaa770e
Show file tree
Hide file tree
Showing 3 changed files with 28 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
=======

2.0.1 (2017-03-21)
------------------

- Fixed AttributeError in WebSocketResponse.can_prepare #1736


2.0.0 (2017-03-20)
------------------

Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def can_prepare(self, request):
raise RuntimeError('Already started')
try:
_, _, _, _, protocol = do_handshake(
request.method, request.headers, request.transport,
request.method, request.headers, request._protocol.writer,
self._protocols)
except HttpProcessingError:
return WebSocketReady(False, None)
Expand Down
21 changes: 21 additions & 0 deletions tests/test_web_websocket_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,32 @@ def ceil(val):
mocker.patch('aiohttp.helpers.ceil').side_effect = ceil


@asyncio.coroutine
def test_websocket_can_prepare(loop, test_client):
@asyncio.coroutine
def handler(request):
ws = web.WebSocketResponse()
if not ws.can_prepare(request):
return web.HTTPUpgradeRequired()

return web.HTTPOk()

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

resp = yield from client.get('/')
assert resp.status == 426


@asyncio.coroutine
def test_websocket_json(loop, test_client):
@asyncio.coroutine
def handler(request):
ws = web.WebSocketResponse()
if not ws.can_prepare(request):
return web.HTTPUpgradeRequired()

yield from ws.prepare(request)
msg = yield from ws.receive()

Expand Down

0 comments on commit eaa770e

Please sign in to comment.