feat: add HTTP_STATUS_CLOSE to support (#816)#817
Merged
Conversation
There was a problem hiding this comment.
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 alongsideHTTP_STATUS_NEXT. - Update
HttpHandlerto transition toWANT_CLOSEwhenHTTP_STATUS_CLOSEis 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_codeis overwritten with the return value fromerrorHandler. This is a behavioral change from the previous implementation (which ignored the return value) and can break error handling if a customerrorHandlerreturnsHTTP_STATUS_NEXT/0 (or any non-HTTP status) after populatingresp—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) orHTTP_STATUS_CLOSE(and never allowingHTTP_STATUS_CLOSEto 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.