mirror of
https://github.com/django/daphne.git
synced 2024-11-21 23:46: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
|
/.tox
|
||||||
.hypothesis
|
.hypothesis
|
||||||
.cache
|
.cache
|
||||||
|
.eggs
|
||||||
|
|
|
@ -350,8 +350,20 @@ class HTTPFactory(http.HTTPFactory):
|
||||||
unknown_keys,
|
unknown_keys,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
# Accepts allow bytes/text afterwards
|
||||||
if message.get("accept", None) and protocol.state == protocol.STATE_CONNECTING:
|
if message.get("accept", None) and protocol.state == protocol.STATE_CONNECTING:
|
||||||
protocol.serverAccept()
|
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):
|
if message.get("bytes", None):
|
||||||
protocol.serverSend(message["bytes"], True)
|
protocol.serverSend(message["bytes"], True)
|
||||||
if message.get("text", None):
|
if message.get("text", None):
|
||||||
|
|
|
@ -175,7 +175,7 @@ class WebSocketProtocol(WebSocketServerProtocol):
|
||||||
|
|
||||||
def serverReject(self):
|
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.handshake_deferred.errback(ConnectionDeny(code=403, reason="Access denied"))
|
||||||
self.cleanup()
|
self.cleanup()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user