Fixed #34752 -- Fixed handling ASGI http.disconnect for streaming responses.

This commit is contained in:
Sam Toyer 2023-07-29 01:43:15 -07:00 committed by Mariusz Felisiak
parent a7c73b944f
commit 64cea1e48f
5 changed files with 197 additions and 23 deletions

View file

@ -1,7 +1,8 @@
import asyncio
import threading
import time
from django.http import FileResponse, HttpResponse
from django.http import FileResponse, HttpResponse, StreamingHttpResponse
from django.urls import path
from django.views.decorators.csrf import csrf_exempt
@ -44,6 +45,17 @@ sync_waiter.lock = threading.Lock()
sync_waiter.barrier = threading.Barrier(2)
async def streaming_inner(sleep_time):
yield b"first\n"
await asyncio.sleep(sleep_time)
yield b"last\n"
async def streaming_view(request):
sleep_time = float(request.GET["sleep"])
return StreamingHttpResponse(streaming_inner(sleep_time))
test_filename = __file__
@ -54,4 +66,5 @@ urlpatterns = [
path("post/", post_echo),
path("wait/", sync_waiter),
path("delayed_hello/", hello_with_delay),
path("streaming/", streaming_view),
]