Skip to content

Commit 1f20654

Browse files
Copilotithewei
andauthored
fix: prevent postprocessor/errorHandler from overriding HTTP_STATUS_UNFINISHED
When a handler returns HTTP_STATUS_UNFINISHED (e.g., sendLargeFile), the postprocessor's return value was overwriting status_code, causing the connection to be treated as complete. This resulted in a premature empty response being sent and the connection being reset/closed. The fix uses local variables for the postprocessor and errorHandler return values, only checking for HTTP_STATUS_CLOSE without modifying status_code. This preserves the UNFINISHED status while still supporting the HTTP_STATUS_CLOSE feature added in commit 62cd137. Agent-Logs-Url: https://github.com/ithewei/libhv/sessions/aa478496-9e54-4c62-b0f7-810817b3867f Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
1 parent 1f32c9d commit 1f20654

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

http/server/HttpHandler.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -486,17 +486,16 @@ int HttpHandler::HandleHttpRequest() {
486486
pResp->status_code = (http_status)status_code;
487487
if (pResp->status_code >= 400 && pResp->body.size() == 0 && pReq->method != HTTP_HEAD) {
488488
if (service->errorHandler) {
489-
status_code = customHttpHandler(service->errorHandler);
489+
int err_status_code = customHttpHandler(service->errorHandler);
490+
if (err_status_code == HTTP_STATUS_CLOSE) {
491+
state = WANT_CLOSE;
492+
return HTTP_STATUS_CLOSE;
493+
}
490494
} else {
491495
defaultErrorHandler();
492496
}
493497
}
494498
}
495-
// Handle HTTP_STATUS_CLOSE: close connection without response
496-
if (status_code == HTTP_STATUS_CLOSE) {
497-
state = WANT_CLOSE;
498-
return HTTP_STATUS_CLOSE;
499-
}
500499
if (fc) {
501500
pResp->content = fc->filebuf.base;
502501
pResp->content_length = fc->filebuf.len;
@@ -505,8 +504,8 @@ int HttpHandler::HandleHttpRequest() {
505504
pResp->headers["Etag"] = fc->etag;
506505
}
507506
if (service->postprocessor) {
508-
status_code = customHttpHandler(service->postprocessor);
509-
if (status_code == HTTP_STATUS_CLOSE) {
507+
int pp_status_code = customHttpHandler(service->postprocessor);
508+
if (pp_status_code == HTTP_STATUS_CLOSE) {
510509
state = WANT_CLOSE;
511510
return HTTP_STATUS_CLOSE;
512511
}

0 commit comments

Comments
 (0)