<div dir="ltr">changeset:   7997:86f70e48a64a<br>branch:      issue-964<br>tag:         tip<br>user:        Yugo Horie <<a href="mailto:yugo-horie@jocdn.co.jp" target="_blank">yugo-horie@jocdn.co.jp</a>><br>date:        Tue Jan 25 12:16:05 2022 +0900<br>files:       src/http/ngx_http_upstream.c src/http/ngx_http_upstream.h<br>description:<br>Prioritize `X-Accel-Expires` than `Cache-Control` and `Expires` (#964)<br><br>We introduce 3 flags that indicate to be overwriting cache control behavior.<br><br>* The `overwrite_noncache` switches on the case of not to be cached when<br>processing `Cache-Control` and `Expires` headers from upstream.<br><br>* The `overwrite_stale_xxx` flags also switch on when it's enabled to use<br>stale cache behavior on processing those headers.<br><br>* `process_accel_expires` watches these flags, which invalidates their non- cache<br>and stale behavior which had been set in other headers to prioritize `X-Accel-Expires`.<br><br>user: Yugo Horie <<a href="mailto:yugo-horie@jocdn.co.jp" target="_blank">yugo-horie@jocdn.co.jp</a>><br>changed src/http/ngx_http_upstream.c<br>changed src/http/ngx_http_upstream.h<br><br><br>diff -r 5d88e2bf92b3 -r 86f70e48a64a src/http/ngx_http_upstream.c<br>--- a/src/http/ngx_http_upstream.c      Sat Jan 22 00:28:51 2022 +0300<br>+++ b/src/http/ngx_http_upstream.c      Tue Jan 25 12:16:05 2022 +0900<br>@@ -4747,6 +4747,7 @@<br>         || ngx_strlcasestrn(start, last, (u_char *) "private", 7 - 1) != NULL)<br>     {<br>         u->cacheable = 0;<br>+        u->overwrite_noncache = 1;<br>         return NGX_OK;<br>     }<br><div><br>@@ -4772,11 +4773,13 @@<br>             }<br><br>             u->cacheable = 0;<br>+            u->overwrite_noncache = 1;<br>             return NGX_OK;<br>         }<br><br>         if (n == 0) {<br>             u->cacheable = 0;<br>+            u->overwrite_noncache = 1;<br>             return NGX_OK;<br>         }<br><br>@@ -4800,9 +4803,12 @@<br>             }<br><br>             u->cacheable = 0;<br>+            u->overwrite_noncache = 1;<br>             return NGX_OK;<br>         }<br><br>+        u->overwrite_stale_updating = 1;<br>+        u->overwrite_stale_error = 1;<br>         r->cache->updating_sec = n;<br>         r->cache->error_sec = n;<br>     }<br>@@ -4822,10 +4828,12 @@<br>                 continue;<br>             }<br><br>+            u->overwrite_noncache = 1;<br>             u->cacheable = 0;<br>             return NGX_OK;<br>         }<br></div><div><br>+        u->overwrite_stale_error = 1;<br>         r->cache->error_sec = n;<br>     }<br>     }<br></div><div>@@ -4863,6 +4871,7 @@<br>     expires = ngx_parse_http_time(h->value.data, h->value.len);<br><br>     if (expires == NGX_ERROR || expires < ngx_time()) {<br>+        u->overwrite_noncache = 1;<br>         u->cacheable = 0;<br>         return NGX_OK;<br>     }<br>@@ -4897,6 +4906,15 @@<br>     if (r->cache == NULL) {<br>         return NGX_OK;<br>     }<br>+    if (u->overwrite_noncache) {<br>+        u->cacheable = 1;<br>+    }<br>+    if (u->overwrite_stale_updating) {<br>+        r->cache->updating_sec = 0;<br>+    }<br>+    if (u->overwrite_stale_error) {<br>+        r->cache->error_sec = 0;<br>+    }<br><br>     len = h->value.len;<br>     p = h->value.data;<br></div><div>diff -r 5d88e2bf92b3 -r 86f70e48a64a src/http/ngx_http_upstream.h<br>--- a/src/http/ngx_http_upstream.h      Sat Jan 22 00:28:51 2022 +0300<br>+++ b/src/http/ngx_http_upstream.h      Tue Jan 25 12:16:05 2022 +0900<br>@@ -386,6 +386,9 @@<br><br>     unsigned                         store:1;<br>     unsigned                         cacheable:1;<br>+    unsigned                         overwrite_noncache:1;<br>+    unsigned                         overwrite_stale_updating:1;<br>+    unsigned                         overwrite_stale_error:1;<br>     unsigned                         accel:1;<br>     unsigned                         ssl:1;<br> #if (NGX_HTTP_CACHE)<br></div></div>