Skip to content

Commit 3a8c195

Browse files
Copilotithewei
andauthored
fix: prevent postprocessor/errorHandler from overriding HTTP_STATUS_UNFINISHED (#828)
* Initial plan * 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> * Refactor postprocessor variable name for clarity --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com> Co-authored-by: ithewei <ithewei@163.com>
1 parent 9eac0bc commit 3a8c195

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

http/server/HttpHandler.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -482,21 +482,25 @@ int HttpHandler::HandleHttpRequest() {
482482
}
483483

484484
postprocessor:
485+
// Handle HTTP_STATUS_CLOSE: close connection without response
486+
if (status_code == HTTP_STATUS_CLOSE) {
487+
state = WANT_CLOSE;
488+
return HTTP_STATUS_CLOSE;
489+
}
485490
if (status_code >= 100 && status_code < 600) {
486491
pResp->status_code = (http_status)status_code;
487492
if (pResp->status_code >= 400 && pResp->body.size() == 0 && pReq->method != HTTP_HEAD) {
488493
if (service->errorHandler) {
489-
status_code = customHttpHandler(service->errorHandler);
494+
int err_status_code = customHttpHandler(service->errorHandler);
495+
if (err_status_code == HTTP_STATUS_CLOSE) {
496+
state = WANT_CLOSE;
497+
return HTTP_STATUS_CLOSE;
498+
}
490499
} else {
491500
defaultErrorHandler();
492501
}
493502
}
494503
}
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-
}
500504
if (fc) {
501505
pResp->content = fc->filebuf.base;
502506
pResp->content_length = fc->filebuf.len;
@@ -505,8 +509,8 @@ int HttpHandler::HandleHttpRequest() {
505509
pResp->headers["Etag"] = fc->etag;
506510
}
507511
if (service->postprocessor) {
508-
status_code = customHttpHandler(service->postprocessor);
509-
if (status_code == HTTP_STATUS_CLOSE) {
512+
int post_status_code = customHttpHandler(service->postprocessor);
513+
if (post_status_code == HTTP_STATUS_CLOSE) {
510514
state = WANT_CLOSE;
511515
return HTTP_STATUS_CLOSE;
512516
}

0 commit comments

Comments
 (0)