mirror of
https://github.com/django/django.git
synced 2025-11-25 05:04:26 +00:00
Fixed #34752 -- Fixed handling ASGI http.disconnect for streaming responses.
This commit is contained in:
parent
a7c73b944f
commit
64cea1e48f
5 changed files with 197 additions and 23 deletions
|
|
@ -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),
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue