Priority of cache-control, expires, x-accel-expires

yugo-horie nginx-forum at forum.nginx.org
Wed Jan 19 02:19:09 UTC 2022


Excuse me for refer to quite old issue, we found a different behavior
regarding their headers order in case of X-Accel-Expires which is not 0 and
Cache-Control has any of no-store, no-cache or private.

It is very easy reproducing process.

ngx_http_upstream.c has two method ngx_http_upstream_process_cache_control
and ngx_http_upstream_process_accel_expires which operations their cache
related headers, Cache-Control is processed in
ngx_http_upstream_process_cache_control, X-Accel-Expires is processed in
process_accel_expires.

ngx_http_upstream_process_cache_control in ngx_http_upstream.c 

4738     if (r->cache->valid_sec != 0 && u->headers_in.x_accel_expires !=
NULL) {
4739         return NGX_OK;
4740     }
4741
4742     start = h->value.data;
4743     last = start + h->value.len;
4744
4745     if (ngx_strlcasestrn(start, last, (u_char *) "no-cache", 8 - 1) !=
NULL
4746         || ngx_strlcasestrn(start, last, (u_char *) "no-store", 8 - 1)
!= NULL
4747         || ngx_strlcasestrn(start, last, (u_char *) "private", 7 - 1)
!= NULL)
4748     {
4749         u->cacheable = 0;
4750         return NGX_OK;
4751     }


If Cache-Control from upstream has  a value of no-store, no-cache or
private, u->cacheable = 0; in ngx_http_upstream_process_cache_control

In the case of before processing ngx_http_upstream_process_accel_expires, if
it sets u->cacheable = 0 for this procedure, it does not cache according to
Cache-Control. X-Accel-Expires is only overwriting valid_sec.

OTOH, In the case of after processing
ngx_http_upstream_process_accel_expires,
ngx_http_upstream_process_cache_control returns NGX_OK earlier than the
procedure of Cache-Control: no-xxx or private. 
In this case, it does cache, the cache is following x-accel-expires values.
It ignores Cache-Control.

As this result it seems not to override entirely Cache-Control by
X-Accel-Expires. And It has differential behavor according to order of
upstream header. We could not find this behavior in any nginx documents.
Could you tell me what is true?

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,219520,293374#msg-293374



More information about the nginx mailing list