Skip to content

feat: add HTTP_STATUS_CLOSE to support (#816)#817

Merged
ithewei merged 2 commits intomasterfrom
feature/http_status_close
Mar 17, 2026
Merged

feat: add HTTP_STATUS_CLOSE to support (#816)#817
ithewei merged 2 commits intomasterfrom
feature/http_status_close

Conversation

@ithewei
Copy link
Owner

@ithewei ithewei commented Mar 17, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 17, 2026 09:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new handler return code to allow HTTP handlers to immediately close the client connection without sending any HTTP response, and wires that behavior into the server-side request handling flow.

Changes:

  • Introduce HTTP_STATUS_CLOSE (=-100) as a new handler return value alongside HTTP_STATUS_NEXT.
  • Update HttpHandler to transition to WANT_CLOSE when HTTP_STATUS_CLOSE is returned (header handler and request handling path).
  • Add an example route (/close) demonstrating connection-close-without-response behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
http/server/HttpService.h Documents and defines the new HTTP_STATUS_CLOSE handler return code.
http/server/HttpHandler.cpp Implements runtime handling of HTTP_STATUS_CLOSE by switching handler state to WANT_CLOSE.
examples/http_server_test.cpp Adds a /close endpoint demonstrating the new behavior.
Comments suppressed due to low confidence (1)

http/server/HttpHandler.cpp:493

  • status_code is overwritten with the return value from errorHandler. This is a behavioral change from the previous implementation (which ignored the return value) and can break error handling if a custom errorHandler returns HTTP_STATUS_NEXT/0 (or any non-HTTP status) after populating resp—the server will treat it as “continue” and skip sending the error response. Consider preserving the original HTTP status unless the handler explicitly returns a valid HTTP status (100–599) or HTTP_STATUS_CLOSE (and never allowing HTTP_STATUS_CLOSE to be overridden).
        if (pResp->status_code >= 400 && pResp->body.size() == 0 && pReq->method != HTTP_HEAD) {
            if (service->errorHandler) {
                status_code = customHttpHandler(service->errorHandler);
            } else {
                defaultErrorHandler();
            }
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 502 to 510
if (service->postprocessor) {
customHttpHandler(service->postprocessor);
status_code = customHttpHandler(service->postprocessor);
}

// Handle HTTP_STATUS_CLOSE: close connection without response
if (status_code == HTTP_STATUS_CLOSE) {
state = WANT_CLOSE;
return HTTP_STATUS_CLOSE;
}
@ithewei ithewei merged commit 62cd137 into master Mar 17, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants