diff --git a/mitmproxy/proxy/protocol/websocket.py b/mitmproxy/proxy/protocol/websocket.py index 15d9a288d..c94763e0f 100644 --- a/mitmproxy/proxy/protocol/websocket.py +++ b/mitmproxy/proxy/protocol/websocket.py @@ -82,7 +82,15 @@ class WebSocketLayer(base.Layer): mask=(False if is_server else 1), masking_key=(b'' if is_server else os.urandom(4))) for i in chunks ] - frms[-1].header.fin = 1 + + if len(frms) > 0: + frms[-1].header.fin = True + else: + frms.append(websockets.Frame( + fin=True, + opcode=frame.header.opcode, + mask=(False if is_server else 1), + masking_key=(b'' if is_server else os.urandom(4)))) for frm in frms: other_conn.send(bytes(frm))