Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions asgiref/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 10 additions & 2 deletions tests/test_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,23 @@ 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.
"""

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 []
Expand Down