diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index bb69e71d0..5fcaa2c33 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -2490,6 +2490,15 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) if (r != r->main) { clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + if (r->buffered || r->postponed) { + + if (ngx_http_set_write_handler(r) != NGX_OK) { + ngx_http_terminate_request(r, 0); + } + + return; + } + if (r->background) { if (!r->logged) { if (clcf->log_subrequest) { @@ -2509,15 +2518,6 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc) return; } - if (r->buffered || r->postponed) { - - if (ngx_http_set_write_handler(r) != NGX_OK) { - ngx_http_terminate_request(r, 0); - } - - return; - } - pr = r->parent; if (r == c->data) {