@@ -331,7 +331,7 @@ void HttpHandler::onMessageComplete() {
331331
332332 if (status_code != HTTP_STATUS_NEXT ) {
333333 // keepalive ? Reset : Close
334- if (keepalive) {
334+ if (error == 0 && keepalive) {
335335 Reset ();
336336 } else {
337337 state = WANT_CLOSE ;
@@ -467,9 +467,9 @@ int HttpHandler::HandleHttpRequest() {
467467 pResp->status_code = (http_status)status_code;
468468 if (pResp->status_code >= 400 && pResp->body .size () == 0 && pReq->method != HTTP_HEAD ) {
469469 if (service->errorHandler ) {
470- customHttpHandler (service->errorHandler );
470+ status_code = customHttpHandler (service->errorHandler );
471471 } else {
472- defaultErrorHandler ();
472+ status_code = defaultErrorHandler ();
473473 }
474474 }
475475 }
@@ -481,7 +481,10 @@ int HttpHandler::HandleHttpRequest() {
481481 pResp->headers [" Etag" ] = fc->etag ;
482482 }
483483 if (service->postprocessor ) {
484- customHttpHandler (service->postprocessor );
484+ status_code = customHttpHandler (service->postprocessor );
485+ }
486+ if (status_code == HTTP_STATUS_WANT_CLOSE ) {
487+ error = ERR_REQUEST ;
485488 }
486489
487490 if (writer && writer->state != hv::HttpResponseWriter::SEND_BEGIN ) {
@@ -853,7 +856,7 @@ int HttpHandler::SendHttpStatusResponse(http_status status_code) {
853856 if (state > WANT_SEND ) return 0 ;
854857 resp->status_code = status_code;
855858 addResponseHeaders ();
856- HandleHttpRequest ();
859+ if ( HandleHttpRequest () == HTTP_STATUS_NEXT ) return 0 ;
857860 state = WANT_SEND ;
858861 return SendHttpResponse ();
859862}
0 commit comments