mirror of
https://github.com/django/daphne.git
synced 2025-07-30 16:59:46 +03:00
Added new argument to runserver to set autobahn handshake timeout (#652)
Allows setting the new option introduced in Daphne.
This commit is contained in:
parent
cd34f650a5
commit
4e8b02955c
|
@ -1,4 +1,5 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ from django import http
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core import signals
|
from django.core import signals
|
||||||
from django.core.handlers import base
|
from django.core.handlers import base
|
||||||
|
|
||||||
from django.http import FileResponse, HttpResponse, HttpResponseServerError
|
from django.http import FileResponse, HttpResponse, HttpResponseServerError
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
|
|
|
@ -25,12 +25,16 @@ class Command(RunserverCommand):
|
||||||
parser.add_argument('--noasgi', action='store_false', dest='use_asgi', default=True,
|
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')
|
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,
|
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):
|
def handle(self, *args, **options):
|
||||||
self.verbosity = options.get("verbosity", 1)
|
self.verbosity = options.get("verbosity", 1)
|
||||||
self.logger = setup_logger('django.channels', self.verbosity)
|
self.logger = setup_logger('django.channels', self.verbosity)
|
||||||
self.http_timeout = options.get("http_timeout", 60)
|
self.http_timeout = options.get("http_timeout", 60)
|
||||||
|
self.websocket_handshake_timeout = options.get("websocket_handshake_timeout", 5)
|
||||||
super(Command, self).handle(*args, **options)
|
super(Command, self).handle(*args, **options)
|
||||||
|
|
||||||
def inner_run(self, *args, **options):
|
def inner_run(self, *args, **options):
|
||||||
|
@ -88,6 +92,7 @@ class Command(RunserverCommand):
|
||||||
http_timeout=self.http_timeout,
|
http_timeout=self.http_timeout,
|
||||||
ws_protocols=getattr(settings, 'CHANNELS_WS_PROTOCOLS', None),
|
ws_protocols=getattr(settings, 'CHANNELS_WS_PROTOCOLS', None),
|
||||||
root_path=getattr(settings, 'FORCE_SCRIPT_NAME', '') or '',
|
root_path=getattr(settings, 'FORCE_SCRIPT_NAME', '') or '',
|
||||||
|
websocket_handshake_timeout=self.websocket_handshake_timeout,
|
||||||
).run()
|
).run()
|
||||||
self.logger.debug("Daphne exited")
|
self.logger.debug("Daphne exited")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import importlib
|
import importlib
|
||||||
from distutils.version import StrictVersion
|
from distutils.version import StrictVersion
|
||||||
|
|
||||||
|
|
||||||
required_versions = {
|
required_versions = {
|
||||||
"asgi_rabbitmq": "0.4.0",
|
"asgi_rabbitmq": "0.4.0",
|
||||||
"asgi_redis": "1.2.0",
|
"asgi_redis": "1.2.0",
|
||||||
|
|
|
@ -4,7 +4,6 @@ import json
|
||||||
import six
|
import six
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from django.http.cookie import SimpleCookie
|
from django.http.cookie import SimpleCookie
|
||||||
|
|
||||||
from ..sessions import session_for_reply_channel
|
from ..sessions import session_for_reply_channel
|
||||||
|
|
|
@ -138,6 +138,7 @@ class RunServerTests(TestCase):
|
||||||
channel_layer=mock.ANY,
|
channel_layer=mock.ANY,
|
||||||
ws_protocols=None,
|
ws_protocols=None,
|
||||||
root_path='',
|
root_path='',
|
||||||
|
websocket_handshake_timeout=5,
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch('channels.management.commands.runserver.sys.stdout', new_callable=StringIO)
|
@mock.patch('channels.management.commands.runserver.sys.stdout', new_callable=StringIO)
|
||||||
|
@ -158,6 +159,7 @@ class RunServerTests(TestCase):
|
||||||
channel_layer=mock.ANY,
|
channel_layer=mock.ANY,
|
||||||
ws_protocols=None,
|
ws_protocols=None,
|
||||||
root_path='',
|
root_path='',
|
||||||
|
websocket_handshake_timeout=5,
|
||||||
)
|
)
|
||||||
|
|
||||||
call_command('runserver', '--noreload', 'localhost:8001')
|
call_command('runserver', '--noreload', 'localhost:8001')
|
||||||
|
@ -169,6 +171,7 @@ class RunServerTests(TestCase):
|
||||||
channel_layer=mock.ANY,
|
channel_layer=mock.ANY,
|
||||||
ws_protocols=None,
|
ws_protocols=None,
|
||||||
root_path='',
|
root_path='',
|
||||||
|
websocket_handshake_timeout=5,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
|
@ -192,6 +195,7 @@ class RunServerTests(TestCase):
|
||||||
channel_layer=mock.ANY,
|
channel_layer=mock.ANY,
|
||||||
ws_protocols=None,
|
ws_protocols=None,
|
||||||
root_path='',
|
root_path='',
|
||||||
|
websocket_handshake_timeout=5,
|
||||||
)
|
)
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
mocked_worker.called,
|
mocked_worker.called,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user