[nginx] Upstream: no last buffer on errors.
Maxim Dounin
mdounin at mdounin.ru
Thu Jul 25 11:59:02 UTC 2013
details: http://hg.nginx.org/nginx/rev/d3eab5e2df5f
branches:
changeset: 5304:d3eab5e2df5f
user: Maxim Dounin <mdounin at mdounin.ru>
date: Thu Jul 25 15:00:41 2013 +0400
description:
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.
diffstat:
src/http/ngx_http_upstream.c | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diffs (36 lines):
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -3297,6 +3297,7 @@ static void
ngx_http_upstream_finalize_request(ngx_http_request_t *r,
ngx_http_upstream_t *u, ngx_int_t rc)
{
+ ngx_uint_t flush;
ngx_time_t *tp;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
@@ -3417,8 +3418,11 @@ ngx_http_upstream_finalize_request(ngx_h
return;
}
- if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
- rc = 0;
+ flush = 0;
+
+ if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
+ rc = NGX_ERROR;
+ flush = 1;
}
if (r->header_only) {
@@ -3428,6 +3432,10 @@ ngx_http_upstream_finalize_request(ngx_h
if (rc == 0) {
rc = ngx_http_send_special(r, NGX_HTTP_LAST);
+
+ } else if (flush) {
+ r->keepalive = 0;
+ rc = ngx_http_send_special(r, NGX_HTTP_FLUSH);
}
ngx_http_finalize_request(r, rc);
More information about the nginx-devel
mailing list