1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[4.1.x] Fixed #33754 -- Fixed crash with prematurely closed ASGI request body.

Regression in 441103a04d.

Backport of f1e0fc645b from main
This commit is contained in:
Jonas Lundberg
2022-05-30 22:45:48 +02:00
committed by Mariusz Felisiak
parent 000e8e0d38
commit 6df6c1b970
4 changed files with 26 additions and 6 deletions

View File

@@ -163,6 +163,18 @@ class ASGITest(SimpleTestCase):
self.assertEqual(response_body["type"], "http.response.body")
self.assertEqual(response_body["body"], b"From Scotland,Wales")
async def test_post_body(self):
application = get_asgi_application()
scope = self.async_request_factory._base_scope(method="POST", path="/post/")
communicator = ApplicationCommunicator(application, scope)
await communicator.send_input({"type": "http.request", "body": b"Echo!"})
response_start = await communicator.receive_output()
self.assertEqual(response_start["type"], "http.response.start")
self.assertEqual(response_start["status"], 200)
response_body = await communicator.receive_output()
self.assertEqual(response_body["type"], "http.response.body")
self.assertEqual(response_body["body"], b"Echo!")
async def test_get_query_string(self):
application = get_asgi_application()
for query_string in (b"name=Andrew", "name=Andrew"):

View File

@@ -2,6 +2,7 @@ import threading
from django.http import FileResponse, HttpResponse
from django.urls import path
from django.views.decorators.csrf import csrf_exempt
def hello(request):
@@ -23,6 +24,11 @@ def sync_waiter(request):
return hello(request)
@csrf_exempt
def post_echo(request):
return HttpResponse(request.body)
sync_waiter.active_threads = set()
sync_waiter.lock = threading.Lock()
sync_waiter.barrier = threading.Barrier(2)
@@ -35,5 +41,6 @@ urlpatterns = [
path("", hello),
path("file/", lambda x: FileResponse(open(test_filename, "rb"))),
path("meta/", hello_meta),
path("post/", post_echo),
path("wait/", sync_waiter),
]