Improve accept flow handling to allow accept: False and match spec

This commit is contained in:
Andrew Godwin 2017-03-27 10:02:18 -07:00
parent 9f4f057e4c
commit bd9b8d0068
3 changed files with 14 additions and 1 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ build/
/.tox
.hypothesis
.cache
.eggs

View File

@ -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):

View File

@ -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()