Skip to content

Commit

Permalink
fix(websocket): ASGI websocket must pass thru bytes as is
Browse files Browse the repository at this point in the history
fix #2644
  • Loading branch information
SaidBySolo committed Jan 8, 2023
1 parent 4ad8168 commit d2a0d7a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sanic/server/websockets/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ async def send(self, data: Union[str, bytes], *args, **kwargs) -> None:

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":
try:
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":
Expand Down

0 comments on commit d2a0d7a

Please sign in to comment.