kopia lustrzana https://github.com/micropython/micropython-lib
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
rodzic
0d838c3a86
commit
da39097756
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
metadata(
|
||||
description="HTTP client module for MicroPython asyncio module",
|
||||
version="0.0.6",
|
||||
version="0.0.7",
|
||||
pypi="aiohttp",
|
||||
)
|
||||
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue