From 1f32c9dbbc9b12af5696c9482e17b9ef204efcfc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 20 Apr 2026 03:31:08 +0000 Subject: [PATCH 1/3] Initial plan From 1f20654fa43baebd35204b2b2790ce54d385587a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 20 Apr 2026 03:43:45 +0000 Subject: [PATCH 2/3] 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> --- http/server/HttpHandler.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/http/server/HttpHandler.cpp b/http/server/HttpHandler.cpp index 005967328..beb048a42 100644 --- a/http/server/HttpHandler.cpp +++ b/http/server/HttpHandler.cpp @@ -486,17 +486,16 @@ int HttpHandler::HandleHttpRequest() { pResp->status_code = (http_status)status_code; if (pResp->status_code >= 400 && pResp->body.size() == 0 && pReq->method != HTTP_HEAD) { if (service->errorHandler) { - status_code = customHttpHandler(service->errorHandler); + int err_status_code = customHttpHandler(service->errorHandler); + if (err_status_code == HTTP_STATUS_CLOSE) { + state = WANT_CLOSE; + return HTTP_STATUS_CLOSE; + } } else { defaultErrorHandler(); } } } - // Handle HTTP_STATUS_CLOSE: close connection without response - if (status_code == HTTP_STATUS_CLOSE) { - state = WANT_CLOSE; - return HTTP_STATUS_CLOSE; - } if (fc) { pResp->content = fc->filebuf.base; pResp->content_length = fc->filebuf.len; @@ -505,8 +504,8 @@ int HttpHandler::HandleHttpRequest() { pResp->headers["Etag"] = fc->etag; } if (service->postprocessor) { - status_code = customHttpHandler(service->postprocessor); - if (status_code == HTTP_STATUS_CLOSE) { + int pp_status_code = customHttpHandler(service->postprocessor); + if (pp_status_code == HTTP_STATUS_CLOSE) { state = WANT_CLOSE; return HTTP_STATUS_CLOSE; } From a80a5361fd4c96e54eb0987a97dbade5699398ae Mon Sep 17 00:00:00 2001 From: ithewei Date: Mon, 20 Apr 2026 11:58:22 +0800 Subject: [PATCH 3/3] Refactor postprocessor variable name for clarity --- http/server/HttpHandler.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/http/server/HttpHandler.cpp b/http/server/HttpHandler.cpp index beb048a42..e9136c1c3 100644 --- a/http/server/HttpHandler.cpp +++ b/http/server/HttpHandler.cpp @@ -482,6 +482,11 @@ int HttpHandler::HandleHttpRequest() { } postprocessor: + // Handle HTTP_STATUS_CLOSE: close connection without response + if (status_code == HTTP_STATUS_CLOSE) { + state = WANT_CLOSE; + return HTTP_STATUS_CLOSE; + } if (status_code >= 100 && status_code < 600) { pResp->status_code = (http_status)status_code; if (pResp->status_code >= 400 && pResp->body.size() == 0 && pReq->method != HTTP_HEAD) { @@ -504,8 +509,8 @@ int HttpHandler::HandleHttpRequest() { pResp->headers["Etag"] = fc->etag; } if (service->postprocessor) { - int pp_status_code = customHttpHandler(service->postprocessor); - if (pp_status_code == HTTP_STATUS_CLOSE) { + int post_status_code = customHttpHandler(service->postprocessor); + if (post_status_code == HTTP_STATUS_CLOSE) { state = WANT_CLOSE; return HTTP_STATUS_CLOSE; }