summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorCarlton Gibson <carlton.gibson@noumenal.es>2023-03-21 20:51:53 +0100
committerGitHub <noreply@github.com>2023-03-21 20:51:53 +0100
commit02c356f2f3945b8075735d485c3cf48cad991011 (patch)
tree61d72336368109a8f4916c5c98fbddb95675706a /django
parenta2eaea8f22305b57dff3ab13add2e2887287bb6f (diff)
downloaddjango-02c356f2f3945b8075735d485c3cf48cad991011.tar.gz
Fixed #34428 -- Made ASGIStaticFilesHandler adapt response to async iterator.
Bug in 0bd2c0c9015b53c41394a1c0989afbfd94dc2830.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/staticfiles/handlers.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/django/contrib/staticfiles/handlers.py b/django/contrib/staticfiles/handlers.py
index cd1cde1fc6..7394eff818 100644
--- a/django/contrib/staticfiles/handlers.py
+++ b/django/contrib/staticfiles/handlers.py
@@ -103,4 +103,13 @@ class ASGIStaticFilesHandler(StaticFilesHandlerMixin, ASGIHandler):
async def get_response_async(self, request):
response = await super().get_response_async(request)
response._resource_closers.append(request.close)
+ # FileResponse is not async compatible.
+ if response.streaming and not response.is_async:
+ _iterator = response.streaming_content
+
+ async def awrapper():
+ for part in await sync_to_async(list)(_iterator):
+ yield part
+
+ response.streaming_content = awrapper()
return response