From 1419f0c6a13eabeb6117743273eb69b5f62fc422 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Fri, 25 Dec 2015 17:50:46 +0200 Subject: [PATCH] Store http code and headers in WSServerHandshakeError --- aiohttp/client.py | 20 ++++++++++++++++---- aiohttp/errors.py | 3 --- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/aiohttp/client.py b/aiohttp/client.py index e9d5209d80..f7e692709e 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -273,20 +273,32 @@ def _ws_connect(self, url, *, try: # check handshake if resp.status != 101: - raise WSServerHandshakeError('Invalid response status') + raise WSServerHandshakeError( + message='Invalid response status', + code=resp.status, + headers=resp.headers) if resp.headers.get(hdrs.UPGRADE, '').lower() != 'websocket': - raise WSServerHandshakeError('Invalid upgrade header') + raise WSServerHandshakeError( + message='Invalid upgrade header', + code=resp.status, + headers=resp.headers) if resp.headers.get(hdrs.CONNECTION, '').lower() != 'upgrade': - raise WSServerHandshakeError('Invalid connection header') + raise WSServerHandshakeError( + message='Invalid connection header', + code=resp.status, + headers=resp.headers) # key calculation key = resp.headers.get(hdrs.SEC_WEBSOCKET_ACCEPT, '') match = base64.b64encode( hashlib.sha1(sec_key + WS_KEY).digest()).decode() if key != match: - raise WSServerHandshakeError('Invalid challenge response') + raise WSServerHandshakeError( + message='Invalid challenge response', + code=resp.status, + headers=resp.headers) # websocket protocol protocol = None diff --git a/aiohttp/errors.py b/aiohttp/errors.py index 930a431112..3f19b6cb89 100644 --- a/aiohttp/errors.py +++ b/aiohttp/errors.py @@ -96,9 +96,6 @@ def __init__(self, *, code=None, message='', headers=None): class WSServerHandshakeError(HttpProcessingError): """websocket server handshake error.""" - def __init__(self, message, *, headers=None): - super().__init__(message=message, headers=headers) - class HttpProxyError(HttpProcessingError): """Http proxy error.