Skip to content

WsgiToAsgi: Set wsgi.input_terminated #286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
@@ -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,
12 changes: 10 additions & 2 deletions tests/test_wsgi.py
Original file line number Diff line number Diff line change
@@ -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 []