diff --git a/channels/handler.py b/channels/handler.py index e6d5734..f43da22 100644 --- a/channels/handler.py +++ b/channels/handler.py @@ -44,7 +44,7 @@ class AsgiRequest(http.HttpRequest): # Path info self.path = self.message['path'] self.script_name = self.message.get('root_path', '') - if self.script_name: + if self.script_name and self.path.startswith(self.script_name): # TODO: Better is-prefix checking, slash handling? self.path_info = self.path[len(self.script_name):] else: diff --git a/channels/management/commands/runserver.py b/channels/management/commands/runserver.py index ac1d783..062ac46 100644 --- a/channels/management/commands/runserver.py +++ b/channels/management/commands/runserver.py @@ -84,6 +84,7 @@ class Command(RunserverCommand): action_logger=self.log_action, http_timeout=self.http_timeout, ws_protocols=getattr(settings, 'CHANNELS_WS_PROTOCOLS', None), + root_path=getattr(settings, 'FORCE_SCRIPT_NAME', ''), ).run() self.logger.debug("Daphne exited") except KeyboardInterrupt: diff --git a/channels/tests/test_management.py b/channels/tests/test_management.py index 6c3f78e..6213caa 100644 --- a/channels/tests/test_management.py +++ b/channels/tests/test_management.py @@ -87,7 +87,7 @@ class RunServerTests(TestCase): call_command('runserver', '--noreload') mocked_server.assert_called_with(port=8000, signal_handlers=True, http_timeout=60, host='127.0.0.1', action_logger=mock.ANY, channel_layer=mock.ANY, - ws_protocols=None) + ws_protocols=None, root_path=None) @mock.patch('channels.management.commands.runserver.sys.stdout', new_callable=StringIO) @mock.patch('channels.management.commands.runserver.Server') @@ -101,12 +101,12 @@ class RunServerTests(TestCase): call_command('runserver', '--noreload') mocked_server.assert_called_with(port=8000, signal_handlers=True, http_timeout=60, host='127.0.0.1', action_logger=mock.ANY, channel_layer=mock.ANY, - ws_protocols=None) + ws_protocols=None, root_path=None) call_command('runserver', '--noreload', 'localhost:8001') mocked_server.assert_called_with(port=8001, signal_handlers=True, http_timeout=60, host='localhost', action_logger=mock.ANY, channel_layer=mock.ANY, - ws_protocols=None) + ws_protocols=None, root_path=None) self.assertFalse(mocked_worker.called, "The worker should not be called with '--noworker'") @@ -121,7 +121,7 @@ class RunServerTests(TestCase): call_command('runserver', '--noreload', '--noworker') mocked_server.assert_called_with(port=8000, signal_handlers=True, http_timeout=60, host='127.0.0.1', action_logger=mock.ANY, channel_layer=mock.ANY, - ws_protocols=None) + ws_protocols=None, root_path=None) self.assertFalse(mocked_worker.called, "The worker should not be called with '--noworker'")