mirror of
https://github.com/django/daphne.git
synced 2024-11-22 16:06:34 +03:00
Hard error on invalid websocket reply messages
This commit is contained in:
parent
6ea3dd803e
commit
45b121572c
|
@ -243,6 +243,15 @@ class HTTPFactory(http.HTTPFactory):
|
||||||
if channel.startswith("http") and isinstance(self.reply_protocols[channel], WebRequest):
|
if channel.startswith("http") and isinstance(self.reply_protocols[channel], WebRequest):
|
||||||
self.reply_protocols[channel].serverResponse(message)
|
self.reply_protocols[channel].serverResponse(message)
|
||||||
elif channel.startswith("websocket") and isinstance(self.reply_protocols[channel], WebSocketProtocol):
|
elif channel.startswith("websocket") and isinstance(self.reply_protocols[channel], WebSocketProtocol):
|
||||||
|
# Ensure the message is a valid WebSocket one
|
||||||
|
unknown_message_keys = set(message.keys()) - {"bytes", "text", "close"}
|
||||||
|
if unknown_message_keys:
|
||||||
|
raise ValueError(
|
||||||
|
"Got invalid WebSocket reply message on %s - contains unknown keys %s" % (
|
||||||
|
channel,
|
||||||
|
unknown_message_keys,
|
||||||
|
)
|
||||||
|
)
|
||||||
if message.get("bytes", None):
|
if message.get("bytes", None):
|
||||||
self.reply_protocols[channel].serverSend(message["bytes"], True)
|
self.reply_protocols[channel].serverSend(message["bytes"], True)
|
||||||
if message.get("text", None):
|
if message.get("text", None):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user