]> git.kaiwu.me - nginx.git/commitdiff
Cache: fix for sending of stale responses.
authorMaxim Dounin <mdounin@mdounin.ru>
Tue, 27 Sep 2011 11:17:11 +0000 (11:17 +0000)
committerMaxim Dounin <mdounin@mdounin.ru>
Tue, 27 Sep 2011 11:17:11 +0000 (11:17 +0000)
For normal cached responses ngx_http_cache_send() sends last buffer and then
request finalized via ngx_http_finalize_request() call, i.e. everything is
ok.

But for stale responses (i.e. when upstream died, but we have something in
cache) the same ngx_http_cache_send() sends last buffer, but then in
ngx_http_upstream_finalize_request() another last buffer is send.  This
causes duplicate final chunk to appear if chunked encoding is used (and
resulting problems with keepalive connections and so on).

Fix this by not sending in ngx_http_upstream_finalize_request()
another last buffer if we know response was from cache.

src/http/ngx_http_upstream.c

index 3d022c78fe60644959942ec28c8bfb9b0a68adb7..703b8ff98a5971a25f2411bbbf7aa0e6fe4126c9 100644 (file)
@@ -3072,7 +3072,12 @@ ngx_http_upstream_finalize_request(ngx_http_request_t *r,
 
     r->connection->log->action = "sending to client";
 
-    if (rc == 0) {
+    if (rc == 0
+#if (NGX_HTTP_CACHE)
+        && !r->cached
+#endif
+       )
+    {
         rc = ngx_http_send_special(r, NGX_HTTP_LAST);
     }