From 527a0b650cc9ea93b266177422ca3f58bd8c4745 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike <111072251+ThomasFarstrike@users.noreply.github.com> Date: Tue, 11 Nov 2025 23:14:52 +0100 Subject: [PATCH] fix: correctly handle WebSocket message fragmentation Handle WebSocket fragmentation was properly by taking into account the "fin" flag to know if a frame is "final" or whether there will be continuations before it's final. Signed-off-by: Thomas Farstrike <111072251+ThomasFarstrike@users.noreply.github.com> --- python-ecosys/aiohttp/aiohttp/aiohttp_ws.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python-ecosys/aiohttp/aiohttp/aiohttp_ws.py b/python-ecosys/aiohttp/aiohttp/aiohttp_ws.py index 53a640fe5..0510f494b 100644 --- a/python-ecosys/aiohttp/aiohttp/aiohttp_ws.py +++ b/python-ecosys/aiohttp/aiohttp/aiohttp_ws.py @@ -166,7 +166,10 @@ async def handshake(self, uri, ssl, req): async def receive(self): while True: - opcode, payload = await self._read_frame() + opcode, payload, final = await self._read_frame() + while not final: + _, morepayload, final = await self._read_frame() # original opcode must be preserved + payload += morepayload send_opcode, data = self._process_websocket_frame(opcode, payload) if send_opcode: # pragma: no cover await self.send(data, send_opcode) @@ -206,7 +209,7 @@ async def _read_frame(self): payload = await self.reader.readexactly(length) if has_mask: # pragma: no cover payload = bytes(x ^ mask[i % 4] for i, x in enumerate(payload)) - return opcode, payload + return opcode, payload, fin class ClientWebSocketResponse: