Skip to content

Commit da39097

Browse files
ThomasFarstrikedpgeorge
authored andcommitted
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 <[email protected]>
1 parent 0d838c3 commit da39097

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

python-ecosys/aiohttp/aiohttp/aiohttp_ws.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ async def handshake(self, uri, ssl, req):
166166

167167
async def receive(self):
168168
while True:
169-
opcode, payload = await self._read_frame()
169+
opcode, payload, final = await self._read_frame()
170+
while not final:
171+
# original opcode must be preserved
172+
_, morepayload, final = await self._read_frame()
173+
payload += morepayload
170174
send_opcode, data = self._process_websocket_frame(opcode, payload)
171175
if send_opcode: # pragma: no cover
172176
await self.send(data, send_opcode)
@@ -206,7 +210,7 @@ async def _read_frame(self):
206210
payload = await self.reader.readexactly(length)
207211
if has_mask: # pragma: no cover
208212
payload = bytes(x ^ mask[i % 4] for i, x in enumerate(payload))
209-
return opcode, payload
213+
return opcode, payload, fin
210214

211215

212216
class ClientWebSocketResponse:

python-ecosys/aiohttp/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
metadata(
22
description="HTTP client module for MicroPython asyncio module",
3-
version="0.0.6",
3+
version="0.0.7",
44
pypi="aiohttp",
55
)
66

0 commit comments

Comments
 (0)