From 53a916e39bed5c4d0afa08591a9a429367207f3a Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Wed, 4 Aug 2021 14:59:48 +0200 Subject: [PATCH] fix websocket regression introduced in 7.0.1 (#4733) --- mitmproxy/proxy/layers/websocket.py | 2 +- test/mitmproxy/proxy/layers/test_websocket.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mitmproxy/proxy/layers/websocket.py b/mitmproxy/proxy/layers/websocket.py index 9a0bb319d..b616eb940 100644 --- a/mitmproxy/proxy/layers/websocket.py +++ b/mitmproxy/proxy/layers/websocket.py @@ -164,7 +164,7 @@ class WebsocketLayer(layer.Layer): content = b"".join(src_ws.frame_buf) fragmentizer = Fragmentizer(src_ws.frame_buf, is_text) - src_ws.frame_buf.clear() + src_ws.frame_buf = [b""] message = websocket.WebSocketMessage(typ, from_client, content) self.flow.websocket.messages.append(message) diff --git a/test/mitmproxy/proxy/layers/test_websocket.py b/test/mitmproxy/proxy/layers/test_websocket.py index 036449330..8b51517ec 100644 --- a/test/mitmproxy/proxy/layers/test_websocket.py +++ b/test/mitmproxy/proxy/layers/test_websocket.py @@ -95,8 +95,12 @@ def test_upgrade(tctx): << websocket.WebsocketMessageHook(flow) >> reply() << SendData(tctx.client, b"\x82\nhello back") + >> DataReceived(tctx.client, masked_bytes(b"\x81\x0bhello again")) + << websocket.WebsocketMessageHook(flow) + >> reply() + << SendData(tctx.server, masked(b"\x81\x0bhello again")) ) - assert len(flow().websocket.messages) == 2 + assert len(flow().websocket.messages) == 3 assert flow().websocket.messages[0].content == b"hello world" assert flow().websocket.messages[0].from_client assert flow().websocket.messages[0].type == Opcode.TEXT