From da3909775653dfcf9627c4126c456426ae5773b9 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] aiohttp: Correctly handle WebSocket message fragmentation. Handle WebSocket fragmentation by 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 | 8 ++++++-- python-ecosys/aiohttp/manifest.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/python-ecosys/aiohttp/aiohttp/aiohttp_ws.py b/python-ecosys/aiohttp/aiohttp/aiohttp_ws.py index 53a640fe5..30fa9ab77 100644 --- a/python-ecosys/aiohttp/aiohttp/aiohttp_ws.py +++ b/python-ecosys/aiohttp/aiohttp/aiohttp_ws.py @@ -166,7 +166,11 @@ 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: + # original opcode must be preserved + _, morepayload, final = await self._read_frame() + 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 +210,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: diff --git a/python-ecosys/aiohttp/manifest.py b/python-ecosys/aiohttp/manifest.py index bbf22bb29..cee6f0c10 100644 --- a/python-ecosys/aiohttp/manifest.py +++ b/python-ecosys/aiohttp/manifest.py @@ -1,6 +1,6 @@ metadata( description="HTTP client module for MicroPython asyncio module", - version="0.0.6", + version="0.0.7", pypi="aiohttp", )