diff --git a/asgiref/wsgi.py b/asgiref/wsgi.py index 40fba205..8fbb4a7d 100644 --- a/asgiref/wsgi.py +++ b/asgiref/wsgi.py @@ -63,6 +63,7 @@ def build_environ(self, scope, body): "wsgi.version": (1, 0), "wsgi.url_scheme": scope.get("scheme", "http"), "wsgi.input": body, + "wsgi.input_terminated": True, # https://gist.github.com/mitsuhiko/5721547 "wsgi.errors": BytesIO(), "wsgi.multithread": True, "wsgi.multiprocess": True, diff --git a/tests/test_wsgi.py b/tests/test_wsgi.py index aabea4df..27c732b2 100644 --- a/tests/test_wsgi.py +++ b/tests/test_wsgi.py @@ -256,7 +256,8 @@ def wsgi_application(environ, start_response): @pytest.mark.asyncio -async def test_wsgi_multi_body(): +@pytest.mark.parametrize("has_content_length", [True, False]) +async def test_wsgi_multi_body(has_content_length): """ Verify that multiple http.request events with body parts are all delivered to the WSGI application. @@ -264,7 +265,14 @@ async def test_wsgi_multi_body(): def wsgi_application(environ, start_response): infp = environ["wsgi.input"] - body = infp.read(12) + if has_content_length: + # this wsgi application reads the content length header and operates on that + body = infp.read(12) + else: + # this wsgi application supports [wsgi.input_terminated](https://gist.github.com/mitsuhiko/5721547) + # and reads until EOF. + assert environ["wsgi.input_terminated"] + body = infp.read() assert body == b"Hello World!" start_response("200 OK", []) return []