diff --git a/daphne/cli.py b/daphne/cli.py index 35db05a..5cd3944 100755 --- a/daphne/cli.py +++ b/daphne/cli.py @@ -36,6 +36,18 @@ class CommandLineInterface(object): help='The host/address to bind to', default=None, ) + self.parser.add_argument( + '--websocket_timeout', + type=int, + help='max time websocket connected. -1 to infinite.', + default=None, + ) + self.parser.add_argument( + '--websocket_connect_timeout', + type=int, + help='max time to refuse establishing connection. -1 to infinite', + default=None, + ) self.parser.add_argument( '-u', '--unix-socket', @@ -186,6 +198,8 @@ class CommandLineInterface(object): http_timeout=args.http_timeout, ping_interval=args.ping_interval, ping_timeout=args.ping_timeout, + websocket_timeout=args.websocket_timeout, + websocket_connect_timeout=args.websocket_connect_timeout, action_logger=AccessLogGenerator(access_log_stream) if access_log_stream else None, ws_protocols=args.ws_protocols, root_path=args.root_path, diff --git a/daphne/http_protocol.py b/daphne/http_protocol.py index 2f82250..8ae044c 100755 --- a/daphne/http_protocol.py +++ b/daphne/http_protocol.py @@ -385,7 +385,7 @@ class HTTPFactory(http.HTTPFactory): # WebSocket timeout checking and keepalive ping sending elif isinstance(protocol, WebSocketProtocol): # Timeout check - if protocol.duration() > self.websocket_timeout: + if protocol.duration() > self.websocket_timeout and self.websocket_timeout >= 0: protocol.serverClose() # Ping check else: diff --git a/daphne/server.py b/daphne/server.py index 7b171b2..2928872 100755 --- a/daphne/server.py +++ b/daphne/server.py @@ -25,6 +25,7 @@ class Server(object): action_logger=None, http_timeout=120, websocket_timeout=None, + websocket_connect_timeout=None, ping_interval=20, ping_timeout=30, ws_protocols=None, @@ -72,6 +73,7 @@ class Server(object): self.action_logger, timeout=self.http_timeout, websocket_timeout=self.websocket_timeout, + websocket_connect_timeout=self.websocket_connect_timeout, ping_interval=self.ping_interval, ping_timeout=self.ping_timeout, ws_protocols=self.ws_protocols,