fix handling of code: invalid unpacking, undefined variable in error path, missing argument

This commit is contained in:
totaam 2019-02-23 12:37:16 +07:00
parent f2031eff05
commit a348b8bf76
1 changed files with 3 additions and 3 deletions

View File

@ -599,7 +599,7 @@ class WebSocket(object):
code = None
reason = None
if len(frame["payload"]) >= 2:
code = struct.unpack(">H", frame["payload"][:2])
code = struct.unpack(">H", frame["payload"][:2])[0]
if len(frame["payload"]) > 2:
reason = frame["payload"][2:]
try:
@ -609,14 +609,14 @@ class WebSocket(object):
continue
if code is None:
self.close_code = 1005
self.close_code = code = 1005
self.close_reason = "No close status code specified by peer"
else:
self.close_code = code
if reason is not None:
self.close_reason = reason
self.shutdown(code, reason)
self.shutdown(None, code, reason)
return None
elif frame["opcode"] == 0x9:
if not frame["fin"]: