Welcome! Log In Create A New Profile


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

January 18, 2022 09:19PM
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 }
4742 start = h->value.data;
4743 last = start + h->value.len;
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?
Subject Author Posted

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

brianmercer December 02, 2011 07:05PM

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

Maxim Dounin December 05, 2011 04:32AM

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

yugo-horie January 18, 2022 09:19PM

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

Maxim Dounin January 19, 2022 08:56AM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 122
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready