@@ -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) {
@@ -671,7 +674,7 @@ int HttpHandler::defaultErrorHandler() {
671674 resp->content_type = TEXT_HTML;
672675 make_http_status_page (resp->status_code , resp->body );
673676 }
674- return 0 ;
677+ return resp-> status_code ;
675678}
676679
677680int HttpHandler::FeedRecvData (const char * data, size_t len) {
@@ -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