Skip to content

Commit

Permalink
Ensure responses are sent with empty bodies for WSGI
Browse files Browse the repository at this point in the history
The previous code was meant to ensure the response was not sent until
the first byte was recevied. However, as the response_body has been
set this should be enough and ensures that empty response bodies work.
  • Loading branch information
pgjones committed May 27, 2024
1 parent a40aa2c commit e47757d
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/hypercorn/app_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ async def handle_http(

def run_app(self, environ: dict, send: Callable) -> None:
headers: List[Tuple[bytes, bytes]]
headers_sent = False
response_started = False
status_code: Optional[int] = None

Expand All @@ -109,12 +108,9 @@ def 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:
for output in response_body:
if not headers_sent:
send({"type": "http.response.start", "status": status_code, "headers": headers})
headers_sent = True

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

0 comments on commit e47757d

Please sign in to comment.