summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/contrib/staticfiles/handlers.py9
-rw-r--r--tests/asgi/tests.py1
2 files changed, 9 insertions, 1 deletions
diff --git a/django/contrib/staticfiles/handlers.py b/django/contrib/staticfiles/handlers.py
index b7d9b5c18d..6343e048d9 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
diff --git a/tests/asgi/tests.py b/tests/asgi/tests.py
index 61d040b45b..f2e293d8bc 100644
--- a/tests/asgi/tests.py
+++ b/tests/asgi/tests.py
@@ -116,7 +116,6 @@ class ASGITest(SimpleTestCase):
"django.contrib.staticfiles.finders.FileSystemFinder",
],
)
- @ignore_warnings(module="django.http.response")
async def test_static_file_response(self):
application = ASGIStaticFilesHandler(get_asgi_application())
# Construct HTTP request.