@@ -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,12 +486,17 @@ 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 }
485493 }
486494 }
495+ // Handle HTTP_STATUS_CLOSE: close connection without response
496+ if (status_code == HTTP_STATUS_CLOSE) {
497+ state = WANT_CLOSE;
498+ return HTTP_STATUS_CLOSE;
499+ }
487500 if (fc) {
488501 pResp->content = fc->filebuf .base ;
489502 pResp->content_length = fc->filebuf .len ;
@@ -492,7 +505,11 @@ int HttpHandler::HandleHttpRequest() {
492505 pResp->headers [" Etag" ] = fc->etag ;
493506 }
494507 if (service->postprocessor ) {
495- customHttpHandler (service->postprocessor );
508+ status_code = customHttpHandler (service->postprocessor );
509+ if (status_code == HTTP_STATUS_CLOSE) {
510+ state = WANT_CLOSE;
511+ return HTTP_STATUS_CLOSE;
512+ }
496513 }
497514
498515 if (writer && writer->state != hv::HttpResponseWriter::SEND_BEGIN) {
@@ -760,7 +777,7 @@ int HttpHandler::GetSendData(char** data, size_t* len) {
760777 if (parser->IsComplete ()) state = WANT_SEND;
761778 else return 0 ;
762779 case HANDLE_END:
763- state = WANT_SEND;
780+ state = WANT_SEND;
764781 case WANT_SEND:
765782 state = SEND_HEADER;
766783 case SEND_HEADER:
0 commit comments