Skip to content

Commit

Permalink
Use code when rejecting connection
Browse files Browse the repository at this point in the history
  • Loading branch information
daveisfera authored Oct 6, 2023
1 parent 2d4dcbf commit 7234cb1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions daphne/ws_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def handle_reply(self, message):
self.serverAccept(message.get("subprotocol", None))
elif message["type"] == "websocket.close":
if self.state == self.STATE_CONNECTING:
self.serverReject()
self.serverReject(code=message.get("code", 403))
else:
self.serverClose(code=message.get("code", None))
elif message["type"] == "websocket.send":
Expand Down Expand Up @@ -222,12 +222,12 @@ def serverAccept(self, subprotocol=None):
del self.handshake_deferred
logger.debug("WebSocket %s accepted by application", self.client_addr)

def serverReject(self):
def serverReject(self, code):
"""
Called when we get a message saying to reject the connection.
"""
self.handshake_deferred.errback(
ConnectionDeny(code=403, reason="Access denied")
ConnectionDeny(code=code, reason="Connection closed")
)
del self.handshake_deferred
self.server.protocol_disconnected(self)
Expand Down Expand Up @@ -284,7 +284,7 @@ def check_timeouts(self):
# If we're still connecting, deny the connection
if self.state == self.STATE_CONNECTING:
if self.duration() > self.server.websocket_connect_timeout:
self.serverReject()
self.serverReject(408)
elif self.state == self.STATE_OPEN:
if (time.time() - self.last_ping) > self.server.ping_interval:
self._sendAutoPing()
Expand Down

0 comments on commit 7234cb1

Please sign in to comment.