mirror of
https://github.com/django/django.git
synced 2025-02-21 14:54:35 +00:00
[4.2.x] Fixed #34428 -- Made ASGIStaticFilesHandler adapt response to async iterator.
Bug in 0bd2c0c9015b53c41394a1c0989afbfd94dc2830. Backport of 02c356f2f3945b8075735d485c3cf48cad991011 from main
This commit is contained in:
parent
e829b0a239
commit
ae824eceb1
@ -103,4 +103,13 @@ class ASGIStaticFilesHandler(StaticFilesHandlerMixin, ASGIHandler):
|
|||||||
async def get_response_async(self, request):
|
async def get_response_async(self, request):
|
||||||
response = await super().get_response_async(request)
|
response = await super().get_response_async(request)
|
||||||
response._resource_closers.append(request.close)
|
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
|
return response
|
||||||
|
@ -116,7 +116,6 @@ class ASGITest(SimpleTestCase):
|
|||||||
"django.contrib.staticfiles.finders.FileSystemFinder",
|
"django.contrib.staticfiles.finders.FileSystemFinder",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@ignore_warnings(module="django.http.response")
|
|
||||||
async def test_static_file_response(self):
|
async def test_static_file_response(self):
|
||||||
application = ASGIStaticFilesHandler(get_asgi_application())
|
application = ASGIStaticFilesHandler(get_asgi_application())
|
||||||
# Construct HTTP request.
|
# Construct HTTP request.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user