diff --git a/CHANGES.rst b/CHANGES.rst index 260a4f22d38..77293f40e59 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,12 @@ Changes ======= +2.0.1 (2017-03-21) +------------------ + +- Fixed AttributeError in WebSocketResponse.can_prepare #1736 + + 2.0.0 (2017-03-20) ------------------ diff --git a/aiohttp/web_ws.py b/aiohttp/web_ws.py index 1ea87d278e1..ad58bc73406 100644 --- a/aiohttp/web_ws.py +++ b/aiohttp/web_ws.py @@ -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) diff --git a/tests/test_web_websocket_functional.py b/tests/test_web_websocket_functional.py index f7627863790..da281ce79e5 100644 --- a/tests/test_web_websocket_functional.py +++ b/tests/test_web_websocket_functional.py @@ -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()