diff options
| author | Sam Toyer <sam@qxcv.net> | 2023-07-29 01:43:15 -0700 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-09-11 19:53:21 +0200 |
| commit | 64cea1e48f285ea2162c669208d95188b32bbc82 (patch) | |
| tree | 490e610188dabdd2fe9b2c9e7d36d51f11002468 /tests/asgi/urls.py | |
| parent | a7c73b944f51d6c92ec876fd7e0a171e7c01657d (diff) | |
Fixed #34752 -- Fixed handling ASGI http.disconnect for streaming responses.
Diffstat (limited to 'tests/asgi/urls.py')
| -rw-r--r-- | tests/asgi/urls.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/asgi/urls.py b/tests/asgi/urls.py index 0f74fc9b97..931b7d5206 100644 --- a/tests/asgi/urls.py +++ b/tests/asgi/urls.py @@ -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), ] |
