Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions django/contrib/staticfiles/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,13 @@ async def __call__(self, scope, receive, send):
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
1 change: 0 additions & 1 deletion tests/asgi/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ async def test_file_response(self):
"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.
Expand Down