Skip to content

Commit e47757d

Browse files
committed
Ensure responses are sent with empty bodies for WSGI
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.
1 parent a40aa2c commit e47757d

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

src/hypercorn/app_wrappers.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ async def handle_http(
8585

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

@@ -109,12 +108,9 @@ def start_response(
109108
if not response_started:
110109
raise RuntimeError("WSGI app did not call start_response")
111110

111+
send({"type": "http.response.start", "status": status_code, "headers": headers})
112112
try:
113113
for output in response_body:
114-
if not headers_sent:
115-
send({"type": "http.response.start", "status": status_code, "headers": headers})
116-
headers_sent = True
117-
118114
send({"type": "http.response.body", "body": output, "more_body": True})
119115
finally:
120116
if hasattr(response_body, "close"):

0 commit comments

Comments
 (0)