[nginx] Cache: fixed caching of intercepted errors (ticket #1382).

Maxim Dounin mdounin at mdounin.ru
Tue Oct 3 16:21:05 UTC 2017


details:   http://hg.nginx.org/nginx/rev/dbd77a638eb7
branches:  
changeset: 7117:dbd77a638eb7
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Tue Oct 03 18:19:27 2017 +0300
description:
Cache: fixed caching of intercepted errors (ticket #1382).

When caching intercepted errors, previous behaviour was to use
proxy_cache_valid times specified, regardless of various cache control
headers present in the response.  Fix is to check u->cacheable and
use u->cache->valid_sec as set by various cache control response headers,
similar to how we do this in the normal caching code path.

diffstat:

 src/http/ngx_http_upstream.c |  24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)

diffs (34 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
@@ -2528,13 +2528,23 @@ ngx_http_upstream_intercept_errors(ngx_h
 #if (NGX_HTTP_CACHE)
 
             if (r->cache) {
-                time_t  valid;
-
-                valid = ngx_http_file_cache_valid(u->conf->cache_valid, status);
-
-                if (valid) {
-                    r->cache->valid_sec = ngx_time() + valid;
-                    r->cache->error = status;
+
+                if (u->cacheable) {
+                    time_t  valid;
+
+                    valid = r->cache->valid_sec;
+
+                    if (valid == 0) {
+                        valid = ngx_http_file_cache_valid(u->conf->cache_valid,
+                                                          status);
+                        if (valid) {
+                            r->cache->valid_sec = ngx_time() + valid;
+                        }
+                    }
+
+                    if (valid) {
+                        r->cache->error = status;
+                    }
                 }
 
                 ngx_http_file_cache_free(r->cache, u->pipe->temp_file);


More information about the nginx-devel mailing list