Upstream: no last buffer on errors.
Previously, after sending a header we always sent a last buffer and
finalized a request with code 0, even in case of errors. In some cases
this resulted in a loss of ability to detect the response wasn't complete
(e.g. if Content-Length was removed from a response by gzip filter).
This change tries to propogate to a client information that a response
isn't complete in such cases. In particular, with this change we no longer
pretend a returned response is complete if we wasn't able to create
a temporary file.
If an error code suggests the error wasn't fatal, we flush buffered data
and disable keepalive, then finalize request normally. This allows to to
propogate information about a problem to a client, while still sending all
the data we've got from an upstream.
Maxim Dounin
8 years ago
3296 | 3296 | ngx_http_upstream_finalize_request(ngx_http_request_t *r, |
3297 | 3297 | ngx_http_upstream_t *u, ngx_int_t rc) |
3298 | 3298 | { |
3299 | ngx_uint_t flush; | |
3299 | 3300 | ngx_time_t *tp; |
3300 | 3301 | |
3301 | 3302 | ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
3416 | 3417 | return; |
3417 | 3418 | } |
3418 | 3419 | |
3419 | if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) { | |
3420 | rc = 0; | |
3420 | flush = 0; | |
3421 | ||
3422 | if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | |
3423 | rc = NGX_ERROR; | |
3424 | flush = 1; | |
3421 | 3425 | } |
3422 | 3426 | |
3423 | 3427 | if (r->header_only) { |
3427 | 3431 | |
3428 | 3432 | if (rc == 0) { |
3429 | 3433 | rc = ngx_http_send_special(r, NGX_HTTP_LAST); |
3434 | ||
3435 | } else if (flush) { | |
3436 | r->keepalive = 0; | |
3437 | rc = ngx_http_send_special(r, NGX_HTTP_FLUSH); | |
3430 | 3438 | } |
3431 | 3439 | |
3432 | 3440 | ngx_http_finalize_request(r, rc); |