Skip to content

Commit 634f339

Browse files
committed
Merge pull request #706 from KeepSafe/wshandshake_error
Store http code and headers in WSServerHandshakeError
2 parents 59453d8 + 1419f0c commit 634f339

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

aiohttp/client.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,20 +273,32 @@ def _ws_connect(self, url, *,
273273
try:
274274
# check handshake
275275
if resp.status != 101:
276-
raise WSServerHandshakeError('Invalid response status')
276+
raise WSServerHandshakeError(
277+
message='Invalid response status',
278+
code=resp.status,
279+
headers=resp.headers)
277280

278281
if resp.headers.get(hdrs.UPGRADE, '').lower() != 'websocket':
279-
raise WSServerHandshakeError('Invalid upgrade header')
282+
raise WSServerHandshakeError(
283+
message='Invalid upgrade header',
284+
code=resp.status,
285+
headers=resp.headers)
280286

281287
if resp.headers.get(hdrs.CONNECTION, '').lower() != 'upgrade':
282-
raise WSServerHandshakeError('Invalid connection header')
288+
raise WSServerHandshakeError(
289+
message='Invalid connection header',
290+
code=resp.status,
291+
headers=resp.headers)
283292

284293
# key calculation
285294
key = resp.headers.get(hdrs.SEC_WEBSOCKET_ACCEPT, '')
286295
match = base64.b64encode(
287296
hashlib.sha1(sec_key + WS_KEY).digest()).decode()
288297
if key != match:
289-
raise WSServerHandshakeError('Invalid challenge response')
298+
raise WSServerHandshakeError(
299+
message='Invalid challenge response',
300+
code=resp.status,
301+
headers=resp.headers)
290302

291303
# websocket protocol
292304
protocol = None

aiohttp/errors.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ def __init__(self, *, code=None, message='', headers=None):
9696
class WSServerHandshakeError(HttpProcessingError):
9797
"""websocket server handshake error."""
9898

99-
def __init__(self, message, *, headers=None):
100-
super().__init__(message=message, headers=headers)
101-
10299

103100
class HttpProxyError(HttpProcessingError):
104101
"""Http proxy error.

0 commit comments

Comments
 (0)