Added new argument to runserver to set autobahn handshake timeout (#652)

Allows setting the new option introduced in Daphne.
This commit is contained in:
ElRoberto538 2017-06-06 05:17:27 +12:00 committed by Andrew Godwin
parent cd34f650a5
commit 4e8b02955c
6 changed files with 11 additions and 4 deletions

View File

@ -1,4 +1,5 @@
from __future__ import unicode_literals
import six

View File

@ -12,7 +12,6 @@ from django import http
from django.conf import settings
from django.core import signals
from django.core.handlers import base
from django.http import FileResponse, HttpResponse, HttpResponseServerError
from django.utils import six
from django.utils.functional import cached_property

View File

@ -25,12 +25,16 @@ class Command(RunserverCommand):
parser.add_argument('--noasgi', action='store_false', dest='use_asgi', default=True,
help='Run the old WSGI-based runserver rather than the ASGI-based one')
parser.add_argument('--http_timeout', action='store', dest='http_timeout', type=int, default=60,
help='Specify the daphane http_timeout interval in seconds (default: 60)')
help='Specify the daphne http_timeout interval in seconds (default: 60)')
parser.add_argument('--websocket_handshake_timeout', action='store', dest='websocket_handshake_timeout',
type=int, default=5,
help='Specify the daphne websocket_handshake_timeout interval in seconds (default: 5)')
def handle(self, *args, **options):
self.verbosity = options.get("verbosity", 1)
self.logger = setup_logger('django.channels', self.verbosity)
self.http_timeout = options.get("http_timeout", 60)
self.websocket_handshake_timeout = options.get("websocket_handshake_timeout", 5)
super(Command, self).handle(*args, **options)
def inner_run(self, *args, **options):
@ -88,6 +92,7 @@ class Command(RunserverCommand):
http_timeout=self.http_timeout,
ws_protocols=getattr(settings, 'CHANNELS_WS_PROTOCOLS', None),
root_path=getattr(settings, 'FORCE_SCRIPT_NAME', '') or '',
websocket_handshake_timeout=self.websocket_handshake_timeout,
).run()
self.logger.debug("Daphne exited")
except KeyboardInterrupt:

View File

@ -1,7 +1,6 @@
import importlib
from distutils.version import StrictVersion
required_versions = {
"asgi_rabbitmq": "0.4.0",
"asgi_redis": "1.2.0",

View File

@ -4,7 +4,6 @@ import json
import six
from django.apps import apps
from django.conf import settings
from django.http.cookie import SimpleCookie
from ..sessions import session_for_reply_channel

View File

@ -138,6 +138,7 @@ class RunServerTests(TestCase):
channel_layer=mock.ANY,
ws_protocols=None,
root_path='',
websocket_handshake_timeout=5,
)
@mock.patch('channels.management.commands.runserver.sys.stdout', new_callable=StringIO)
@ -158,6 +159,7 @@ class RunServerTests(TestCase):
channel_layer=mock.ANY,
ws_protocols=None,
root_path='',
websocket_handshake_timeout=5,
)
call_command('runserver', '--noreload', 'localhost:8001')
@ -169,6 +171,7 @@ class RunServerTests(TestCase):
channel_layer=mock.ANY,
ws_protocols=None,
root_path='',
websocket_handshake_timeout=5,
)
self.assertFalse(
@ -192,6 +195,7 @@ class RunServerTests(TestCase):
channel_layer=mock.ANY,
ws_protocols=None,
root_path='',
websocket_handshake_timeout=5,
)
self.assertFalse(
mocked_worker.called,