diff --git a/django/core/handlers/asgi.py b/django/core/handlers/asgi.py index 3af080599ab..bb6a6bfb3ce 100644 --- a/django/core/handlers/asgi.py +++ b/django/core/handlers/asgi.py @@ -50,21 +50,13 @@ class ASGIRequest(HttpRequest): self._post_parse_error = False self._read_started = False self.resolver_match = None + self.path = scope["path"] self.script_name = get_script_prefix(scope) if self.script_name: # TODO: Better is-prefix checking, slash handling? self.path_info = scope["path"].removeprefix(self.script_name) else: self.path_info = scope["path"] - # The Django path is different from ASGI scope path args, it should - # combine with script name. - if self.script_name: - self.path = "%s/%s" % ( - self.script_name.rstrip("/"), - self.path_info.replace("/", "", 1), - ) - else: - self.path = scope["path"] # HTTP basics. self.method = self.scope["method"].upper() # Ensure query string is encoded correctly. diff --git a/tests/handlers/tests.py b/tests/handlers/tests.py index 959e4737d25..ffa362abdd7 100644 --- a/tests/handlers/tests.py +++ b/tests/handlers/tests.py @@ -335,11 +335,13 @@ class AsyncHandlerRequestTests(SimpleTestCase): self.assertEqual(request.script_name, "/root") self.assertEqual(request.path_info, "/somepath/") - @override_settings(FORCE_SCRIPT_NAME="/FORCED_PREFIX/") + @override_settings(FORCE_SCRIPT_NAME="/FORCED_PREFIX") def test_force_script_name(self): async_request_factory = AsyncRequestFactory() - request = async_request_factory.request(**{"path": "/somepath/"}) + request = async_request_factory.request(**{"path": "/FORCED_PREFIX/somepath/"}) self.assertEqual(request.path, "/FORCED_PREFIX/somepath/") + self.assertEqual(request.script_name, "/FORCED_PREFIX") + self.assertEqual(request.path_info, "/somepath/") async def test_sync_streaming(self): response = await self.async_client.get("/streaming/")