mirror of
https://github.com/frappe/gunicorn.git
synced 2026-07-03 19:21:29 +08:00
Fix WebSocket binary send when text key is None
ASGI allows websocket.send messages to contain both text and bytes keys where one is None. Check for truthy values instead of key existence.
This commit is contained in:
parent
746cc049d0
commit
725c03e8ff
@ -145,10 +145,13 @@ class WebSocketProtocol:
|
||||
if self.closed:
|
||||
raise RuntimeError("WebSocket closed")
|
||||
|
||||
if "text" in message:
|
||||
await self._send_frame(OPCODE_TEXT, message["text"].encode("utf-8"))
|
||||
elif "bytes" in message:
|
||||
await self._send_frame(OPCODE_BINARY, message["bytes"])
|
||||
# Check for truthy values since both keys may be present with None
|
||||
text = message.get("text")
|
||||
bytes_data = message.get("bytes")
|
||||
if text is not None:
|
||||
await self._send_frame(OPCODE_TEXT, text.encode("utf-8"))
|
||||
elif bytes_data is not None:
|
||||
await self._send_frame(OPCODE_BINARY, bytes_data)
|
||||
|
||||
elif msg_type == "websocket.close":
|
||||
code = message.get("code", CLOSE_NORMAL)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user