Skip to content
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
12 changes: 8 additions & 4 deletions src/hypercorn/app_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,16 @@ def start_response(

response_body = self.app(environ, start_response)

if not response_started:
raise RuntimeError("WSGI app did not call start_response")

send({"type": "http.response.start", "status": status_code, "headers": headers})
try:
first_chunk = True
for output in response_body:
if first_chunk:
if not response_started:
raise RuntimeError("WSGI app did not call start_response")

send({"type": "http.response.start", "status": status_code, "headers": headers})
first_chunk = False

send({"type": "http.response.body", "body": output, "more_body": True})
finally:
if hasattr(response_body, "close"):
Expand Down