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>
pull/1057/head
Thomas Farstrike 2025-11-11 23:14:52 +01:00 zatwierdzone przez Damien George
rodzic 0d838c3a86
commit da39097756
2 zmienionych plików z 7 dodań i 3 usunięć

Wyświetl plik

@ -166,7 +166,11 @@ class WebSocketClient:
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 @@ class WebSocketClient:
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:

Wyświetl plik

@ -1,6 +1,6 @@
metadata(
description="HTTP client module for MicroPython asyncio module",
version="0.0.6",
version="0.0.7",
pypi="aiohttp",
)