@@ -254,6 +254,10 @@ void HttpHandler::onHeadersComplete() {
254254 handleRequestHeaders ();
255255 if (service->headerHandler ) {
256256 const int status_code = customHttpHandler (service->headerHandler );
257+ if (status_code == HTTP_STATUS_CLOSE) {
258+ state = WANT_CLOSE;
259+ return ;
260+ }
257261 if (status_code != HTTP_STATUS_OK && status_code != HTTP_STATUS_NEXT) {
258262 SetError (ERR_REQUEST, static_cast <http_status>(status_code));
259263 return ;
@@ -338,6 +342,10 @@ void HttpHandler::onMessageComplete() {
338342 }
339343 } else {
340344 status_code = HandleHttpRequest ();
345+ if (status_code == HTTP_STATUS_CLOSE) {
346+ state = WANT_CLOSE;
347+ return ;
348+ }
341349 if (status_code != HTTP_STATUS_NEXT) {
342350 SendHttpResponse ();
343351 }
@@ -478,7 +486,7 @@ int HttpHandler::HandleHttpRequest() {
478486 pResp->status_code = (http_status)status_code;
479487 if (pResp->status_code >= 400 && pResp->body .size () == 0 && pReq->method != HTTP_HEAD) {
480488 if (service->errorHandler ) {
481- customHttpHandler (service->errorHandler );
489+ status_code = customHttpHandler (service->errorHandler );
482490 } else {
483491 defaultErrorHandler ();
484492 }
@@ -492,7 +500,13 @@ int HttpHandler::HandleHttpRequest() {
492500 pResp->headers [" Etag" ] = fc->etag ;
493501 }
494502 if (service->postprocessor ) {
495- customHttpHandler (service->postprocessor );
503+ status_code = customHttpHandler (service->postprocessor );
504+ }
505+
506+ // Handle HTTP_STATUS_CLOSE: close connection without response
507+ if (status_code == HTTP_STATUS_CLOSE) {
508+ state = WANT_CLOSE;
509+ return HTTP_STATUS_CLOSE;
496510 }
497511
498512 if (writer && writer->state != hv::HttpResponseWriter::SEND_BEGIN) {
@@ -760,7 +774,7 @@ int HttpHandler::GetSendData(char** data, size_t* len) {
760774 if (parser->IsComplete ()) state = WANT_SEND;
761775 else return 0 ;
762776 case HANDLE_END:
763- state = WANT_SEND;
777+ state = WANT_SEND;
764778 case WANT_SEND:
765779 state = SEND_HEADER;
766780 case SEND_HEADER:
0 commit comments