mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
fix: correctly handle WebSocket message fragmentation #1057
This commit is contained in:
@@ -166,7 +166,10 @@ class WebSocketClient:
|
||||
|
||||
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 @@ 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:
|
||||
|
||||
Reference in New Issue
Block a user