fix(websocket): ASGI websocket must pass thru bytes as is (#2651)

This commit is contained in:
Ryu Juheon
2023-02-05 23:41:54 +09:00
committed by GitHub
parent c7a71cd00c
commit 5e7f6998bd
2 changed files with 12 additions and 3 deletions

View File

@@ -45,7 +45,7 @@ class WebSocketConnection:
await self._send(message)
async def recv(self, *args, **kwargs) -> Optional[str]:
async def recv(self, *args, **kwargs) -> Optional[Union[str, bytes]]:
message = await self._receive()
if message["type"] == "websocket.receive":
@@ -53,7 +53,7 @@ class WebSocketConnection:
return message["text"]
except KeyError:
try:
return message["bytes"].decode()
return message["bytes"]
except KeyError:
raise InvalidUsage("Bad ASGI message received")
elif message["type"] == "websocket.disconnect":