Skip to content

Commit d3786eb

Browse files
ITcarrotpgjones
authored andcommitted
Delay sending http headers
1 parent 7bdaebf commit d3786eb

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/hypercorn/app_wrappers.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,16 @@ def start_response(
105105

106106
response_body = self.app(environ, start_response)
107107

108-
if not response_started:
109-
raise RuntimeError("WSGI app did not call start_response")
110-
111-
send({"type": "http.response.start", "status": status_code, "headers": headers})
112108
try:
109+
first_chunk = True
113110
for output in response_body:
111+
if first_chunk:
112+
if not response_started:
113+
raise RuntimeError("WSGI app did not call start_response")
114+
115+
send({"type": "http.response.start", "status": status_code, "headers": headers})
116+
first_chunk = False
117+
114118
send({"type": "http.response.body", "body": output, "more_body": True})
115119
finally:
116120
if hasattr(response_body, "close"):

0 commit comments

Comments
 (0)