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 /.tox
.hypothesis .hypothesis
.cache .cache
.eggs

View File

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

View File

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