[nginx] svn commit: r4249 - in branches/stable-1.0: . src/http

igor at sysoev.ru igor at sysoev.ru
Tue Nov 1 13:49:31 UTC 2011


Author: is
Date: 2011-11-01 13:49:31 +0000 (Tue, 01 Nov 2011)
New Revision: 4249

Modified:
   branches/stable-1.0/
   branches/stable-1.0/src/http/ngx_http_file_cache.c
   branches/stable-1.0/src/http/ngx_http_upstream.c
Log:
Merging r4151, r4152, r4177:

HTTP cache related fixes:

*) Cache: fix for sending of empty responses.

   Revert wrong fix for empty responses introduced in 0.8.31 and apply new
   one, rewritten to match things done by static module as close as possible.
   
*) Cache: fix for sending of stale responses.
   
   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.
   
*) Fixed cache bypass caching of non-cacheable replies (ticket #21).
   
   If cache was bypassed with proxy_cache_bypass, cache-controlling headers
   (Cache-Control, Expires) wasn't considered and response was cached even
   if it was actually non-cacheable.
   
   Patch by John Ferlito.



Property changes on: branches/stable-1.0
___________________________________________________________________
Modified: svn:mergeinfo
   - /trunk:3960-3974,3977-3987,3991-3996,3998,4003-4007,4009-4013,4015-4018,4020,4023,4025-4027,4034-4065,4073,4077,4086-4090,4094-4102,4106-4108,4113-4114,4129-4137,4143,4147-4150,4154,4156-4157,4183-4184,4186-4187,4191-4192,4199-4205,4207,4229,4235,4237
   + /trunk:3960-3974,3977-3987,3991-3996,3998,4003-4007,4009-4013,4015-4018,4020,4023,4025-4027,4034-4065,4073,4077,4086-4090,4094-4102,4106-4108,4113-4114,4129-4137,4143,4147-4152,4154,4156-4157,4177,4183-4184,4186-4187,4191-4192,4199-4205,4207,4229,4235,4237

Modified: branches/stable-1.0/src/http/ngx_http_file_cache.c
===================================================================
--- branches/stable-1.0/src/http/ngx_http_file_cache.c	2011-11-01 13:45:33 UTC (rev 4248)
+++ branches/stable-1.0/src/http/ngx_http_file_cache.c	2011-11-01 13:49:31 UTC (rev 4249)
@@ -854,6 +854,10 @@
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                    "http file cache send: %s", c->file.name.data);
 
+    if (r != r->main && c->length - c->body_start == 0) {
+        return ngx_http_send_header(r);
+    }
+
     /* we need to allocate all before the header would be sent */
 
     b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
@@ -866,8 +870,6 @@
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
 
-    r->header_only = (c->length - c->body_start) == 0;
-
     rc = ngx_http_send_header(r);
 
     if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
@@ -877,7 +879,7 @@
     b->file_pos = c->body_start;
     b->file_last = c->length;
 
-    b->in_file = 1;
+    b->in_file = (c->length - c->body_start) ? 1: 0;
     b->last_buf = (r == r->main) ? 1: 0;
     b->last_in_chain = 1;
 

Modified: branches/stable-1.0/src/http/ngx_http_upstream.c
===================================================================
--- branches/stable-1.0/src/http/ngx_http_upstream.c	2011-11-01 13:45:33 UTC (rev 4248)
+++ branches/stable-1.0/src/http/ngx_http_upstream.c	2011-11-01 13:49:31 UTC (rev 4249)
@@ -672,6 +672,8 @@
             return NGX_DECLINED;
         }
 
+        u->cacheable = 1;
+
         switch (ngx_http_test_predicates(r, u->conf->cache_bypass)) {
 
         case NGX_ERROR:
@@ -685,8 +687,6 @@
             break;
         }
 
-        u->cacheable = 1;
-
         c = r->cache;
 
         c->min_uses = u->conf->cache_min_uses;
@@ -2154,8 +2154,6 @@
                 ngx_http_upstream_finalize_request(r, u, 0);
                 return;
             }
-
-            u->cacheable = 1;
         }
 
         break;
@@ -3027,7 +3025,12 @@
 
     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);
     }
 



More information about the nginx-devel mailing list