diff options
Diffstat (limited to 'django/core/handlers/asgi.py')
| -rw-r--r-- | django/core/handlers/asgi.py | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/django/core/handlers/asgi.py b/django/core/handlers/asgi.py index bb782dad9b..82d2e1ab9d 100644 --- a/django/core/handlers/asgi.py +++ b/django/core/handlers/asgi.py @@ -1,4 +1,3 @@ -import asyncio import logging import sys import tempfile @@ -132,7 +131,7 @@ class ASGIHandler(base.BaseHandler): def __init__(self): super().__init__() - self.load_middleware() + self.load_middleware(is_async=True) async def __call__(self, scope, receive, send): """ @@ -158,12 +157,8 @@ class ASGIHandler(base.BaseHandler): if request is None: await self.send_response(error_response, send) return - # Get the response, using a threadpool via sync_to_async, if needed. - if asyncio.iscoroutinefunction(self.get_response): - response = await self.get_response(request) - else: - # If get_response is synchronous, run it non-blocking. - response = await sync_to_async(self.get_response)(request) + # Get the response, using the async mode of BaseHandler. + response = await self.get_response_async(request) response._handler_class = self.__class__ # Increase chunk size on file responses (ASGI servers handles low-level # chunking). @@ -264,7 +259,7 @@ class ASGIHandler(base.BaseHandler): 'body': chunk, 'more_body': not last, }) - response.close() + await sync_to_async(response.close)() @classmethod def chunk_bytes(cls, data): |
