Welcome! Log In Create A New Profile

Advanced

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Maxim Dounin
April 16, 2022 09:56PM
Hello!

On Fri, Apr 15, 2022 at 02:02:53AM +0300, Vadim Fedorenko via nginx-devel wrote:

> # HG changeset patch
> # User Vadim Fedorenko <vadim.fedorenko@cdnnow.ru>
> # Date 1649889268 -10800
> # Thu Apr 14 01:34:28 2022 +0300
> # Node ID ed7a2c031475bcb252952a467c184c94652b926a
> # Parent a736a7a613ea6e182ff86fbadcb98bb0f8891c0b
> Upstream: prioritise Cache-Control over Expires.
>
> RFC7234 explicitly says that cache recipient MUST ignore Expires
> header if response includes Cache-Control header with max-age or
> s-maxage directives. Previously Cache-Control was ignored if it
> was after Expires in reply headers.
>
> At the same time this patch makes more stable behaviour of using
> latest value of header Cache-Control even if previous value was 0.
> Ticket #964 for more information.
> ---
> src/http/ngx_http_upstream.c | 25 +++++++++++++++++++++++++
> src/http/ngx_http_upstream.h | 15 +++++++++++++++
> 2 files changed, 40 insertions(+)
>
> diff -r a736a7a613ea -r ed7a2c031475 src/http/ngx_http_upstream.c
> --- a/src/http/ngx_http_upstream.c Tue Feb 08 17:35:27 2022 +0300
> +++ b/src/http/ngx_http_upstream.c Thu Apr 14 01:34:28 2022 +0300
> @@ -868,6 +868,7 @@
> }
>
> u->cacheable = 1;
> + u->cacheable_reason |= NGX_HTTP_CACHEABLE_DEFAULT;
>
> c = r->cache;
>
> @@ -970,6 +971,7 @@
> case NGX_HTTP_CACHE_SCARCE:
>
> u->cacheable = 0;
> + u->cacheable_reason |= NGX_HTTP_CACHEABLE_SCARCE;
>
> break;
>
> @@ -992,6 +994,7 @@
>
> if (ngx_http_upstream_cache_check_range(r, u) == NGX_DECLINED) {
> u->cacheable = 0;
> + u->cacheable_reason |= NGX_HTTP_CACHEABLE_RANGE;
> }
>
> r->cached = 0;
> @@ -3105,6 +3108,7 @@
>
> case NGX_DECLINED:
> u->cacheable = 0;
> + u->cacheable_reason |= NGX_HTTP_CACHEABLE_NO_CACHE;
> break;
>
> default: /* NGX_OK */
> @@ -3165,6 +3169,7 @@
>
> } else {
> u->cacheable = 0;
> + u->cacheable_reason |= NGX_HTTP_CACHEABLE_INVALID;
> }
> }
>
> @@ -4690,6 +4695,7 @@
> #if (NGX_HTTP_CACHE)
> if (!(u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_SET_COOKIE)) {
> u->cacheable = 0;
> + u->cacheable_reason |= NGX_HTTP_CACHEABLE_COOKIE;
> }
> #endif
>
> @@ -4747,6 +4753,7 @@
> || ngx_strlcasestrn(start, last, (u_char *) "private", 7 - 1) != NULL)
> {
> u->cacheable = 0;
> + u->cacheable_reason |= NGX_HTTP_CACHEABLE_NO_CACHE;
> return NGX_OK;
> }
>
> @@ -4772,15 +4779,21 @@
> }
>
> u->cacheable = 0;
> + u->cacheable_reason |= NGX_HTTP_CACHEABLE_CACHECTRL0;
> return NGX_OK;
> }
>
> if (n == 0) {
> u->cacheable = 0;
> + u->cacheable_reason |= NGX_HTTP_CACHEABLE_CACHECTRL0;
> return NGX_OK;
> }
>
> r->cache->valid_sec = ngx_time() + n;
> + u->cacheable_reason &= ~(NGX_HTTP_CACHEABLE_CACHECTRL0|NGX_HTTP_CACHEABLE_EXPIRES);
> + if (u->cacheable_reason == NGX_HTTP_CACHEABLE_DEFAULT) {
> + u->cacheable = 1;
> + }
> }
>
> p = ngx_strlcasestrn(start, last, (u_char *) "stale-while-revalidate=",

[...]

Thanks for the patch.

I'm quite sceptical about attempts to fix this by introducing
various flags and reverting cacheable status back to 1. This is
not how it should be fixed.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[PATCH] Upstream: prioritise Cache-Control over Expires

Vadim Fedorenko via nginx-devel 1100 April 14, 2022 07:04PM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Maxim Dounin 158 April 16, 2022 09:56PM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Vadim Fedorenko via nginx-devel 188 April 17, 2022 03:52PM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

yugo-horie 232 April 17, 2022 09:16PM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Vadim Fedorenko via nginx-devel 213 April 18, 2022 06:22AM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

yugo-horie 200 April 18, 2022 07:04PM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Maxim Dounin 275 April 19, 2022 11:02AM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Maxim Dounin 140 April 22, 2022 02:24PM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Vadim Fedorenko via nginx-devel 252 April 22, 2022 03:08PM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Maxim Dounin 162 April 24, 2022 12:56AM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Maxim Dounin 148 April 24, 2022 11:44AM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

yugo-horie 190 April 25, 2022 08:28AM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Vadim Fedorenko via nginx-devel 194 April 25, 2022 05:04PM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Vadim Fedorenko via nginx-devel 166 April 25, 2022 05:08PM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Sergey Kandaurov 142 June 06, 2022 09:44AM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Sergey Kandaurov 119 June 06, 2022 10:42AM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Maxim Dounin 138 June 06, 2022 05:10PM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Sergey Kandaurov 166 June 07, 2022 12:02PM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Maxim Dounin 176 June 07, 2022 09:00PM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Sergey Kandaurov 158 June 10, 2022 07:40AM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Maxim Dounin 132 June 11, 2022 06:54PM

Re: [PATCH] Upstream: prioritise Cache-Control over Expires

Sergey Kandaurov 168 June 13, 2022 07:42AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 115
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