Skip to content

支持 http 处理链返回 HTTP_STATUS_WANT_CLOSE #716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions http/server/HttpHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void HttpHandler::onMessageComplete() {

if (status_code != HTTP_STATUS_NEXT) {
// keepalive ? Reset : Close
if (keepalive) {
if (error == 0 && keepalive) {
Reset();
} else {
state = WANT_CLOSE;
Expand Down Expand Up @@ -467,9 +467,9 @@ 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) {
customHttpHandler(service->errorHandler);
status_code = customHttpHandler(service->errorHandler);
} else {
defaultErrorHandler();
status_code = defaultErrorHandler();
}
}
}
Expand All @@ -481,7 +481,10 @@ int HttpHandler::HandleHttpRequest() {
pResp->headers["Etag"] = fc->etag;
}
if (service->postprocessor) {
customHttpHandler(service->postprocessor);
status_code = customHttpHandler(service->postprocessor);
}
if (status_code == HTTP_STATUS_WANT_CLOSE) {
error = ERR_REQUEST;
}

if (writer && writer->state != hv::HttpResponseWriter::SEND_BEGIN) {
Expand Down Expand Up @@ -671,7 +674,7 @@ int HttpHandler::defaultErrorHandler() {
resp->content_type = TEXT_HTML;
make_http_status_page(resp->status_code, resp->body);
}
return 0;
return resp->status_code;
}

int HttpHandler::FeedRecvData(const char* data, size_t len) {
Expand Down Expand Up @@ -853,7 +856,7 @@ int HttpHandler::SendHttpStatusResponse(http_status status_code) {
if (state > WANT_SEND) return 0;
resp->status_code = status_code;
addResponseHeaders();
HandleHttpRequest();
if (HandleHttpRequest() == HTTP_STATUS_NEXT) return 0;
state = WANT_SEND;
return SendHttpResponse();
}
Expand Down
1 change: 1 addition & 0 deletions http/server/HttpService.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/
#define HTTP_STATUS_NEXT 0
#define HTTP_STATUS_UNFINISHED 0
#define HTTP_STATUS_WANT_CLOSE 1
// NOTE: http_sync_handler run on IO thread
typedef std::function<int(HttpRequest* req, HttpResponse* resp)> http_sync_handler;
// NOTE: http_async_handler run on hv::async threadpool
Expand Down