mirror of
https://github.com/django/daphne.git
synced 2024-11-21 15:36:33 +03:00
Improve accept flow handling to allow accept: False and match spec
This commit is contained in:
parent
9f4f057e4c
commit
bd9b8d0068
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,3 +6,4 @@ build/
|
|||
/.tox
|
||||
.hypothesis
|
||||
.cache
|
||||
.eggs
|
||||
|
|
|
@ -350,8 +350,20 @@ class HTTPFactory(http.HTTPFactory):
|
|||
unknown_keys,
|
||||
)
|
||||
)
|
||||
# Accepts allow bytes/text afterwards
|
||||
if message.get("accept", None) and protocol.state == protocol.STATE_CONNECTING:
|
||||
protocol.serverAccept()
|
||||
# Rejections must be the only thing
|
||||
if message.get("accept", None) == False and protocol.state == protocol.STATE_CONNECTING:
|
||||
protocol.serverReject()
|
||||
return
|
||||
# You're only allowed one of bytes or text
|
||||
if message.get("bytes", None) and message.get("text", None):
|
||||
raise ValueError(
|
||||
"Got invalid WebSocket reply message on %s - contains both bytes and text keys" % (
|
||||
channel,
|
||||
)
|
||||
)
|
||||
if message.get("bytes", None):
|
||||
protocol.serverSend(message["bytes"], True)
|
||||
if message.get("text", None):
|
||||
|
|
|
@ -175,7 +175,7 @@ class WebSocketProtocol(WebSocketServerProtocol):
|
|||
|
||||
def serverReject(self):
|
||||
"""
|
||||
Called when we get a message saying to accept the connection.
|
||||
Called when we get a message saying to reject the connection.
|
||||
"""
|
||||
self.handshake_deferred.errback(ConnectionDeny(code=403, reason="Access denied"))
|
||||
self.cleanup()
|
||||
|
|
Loading…
Reference in New Issue
Block a user