[PATCH] Cache: add support for Cache-Control's s-maxage response directive
Piotr Sikora
piotr at cloudflare.com
Wed Nov 19 01:15:51 UTC 2014
# HG changeset patch
# User Piotr Sikora <piotr at cloudflare.com>
# Date 1416359234 28800
# Tue Nov 18 17:07:14 2014 -0800
# Node ID b7b345ad11d81cbf6c17e5933aad9ce3af4f16c8
# Parent 2f7e557eab5b501ba71418febd3de9ef1c0ab4f1
Cache: add support for Cache-Control's s-maxage response directive.
Signed-off-by: Piotr Sikora <piotr at cloudflare.com>
diff -r 2f7e557eab5b -r b7b345ad11d8 src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c Tue Nov 18 20:41:12 2014 +0300
+++ b/src/http/ngx_http_upstream.c Tue Nov 18 17:07:14 2014 -0800
@@ -3934,7 +3934,7 @@ ngx_http_upstream_process_cache_control(
#if (NGX_HTTP_CACHE)
{
- u_char *p, *last;
+ u_char *p, *start, *last;
ngx_int_t n;
if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL) {
@@ -3949,18 +3949,24 @@ ngx_http_upstream_process_cache_control(
return NGX_OK;
}
- p = h->value.data;
- last = p + h->value.len;
-
- if (ngx_strlcasestrn(p, last, (u_char *) "no-cache", 8 - 1) != NULL
- || ngx_strlcasestrn(p, last, (u_char *) "no-store", 8 - 1) != NULL
- || ngx_strlcasestrn(p, last, (u_char *) "private", 7 - 1) != NULL)
+ start = h->value.data;
+ last = start + h->value.len;
+
+ if (ngx_strlcasestrn(start, last, (u_char *) "no-cache", 8 - 1) != NULL
+ || ngx_strlcasestrn(start, last, (u_char *) "no-store", 8 - 1) != NULL
+ || ngx_strlcasestrn(start, last, (u_char *) "private", 7 - 1) != NULL)
{
u->cacheable = 0;
return NGX_OK;
}
- p = ngx_strlcasestrn(p, last, (u_char *) "max-age=", 8 - 1);
+ p = ngx_strlcasestrn(start, last, (u_char *) "s-maxage=", 9 - 1);
+ offset = 9;
+
+ if (p == NULL) {
+ p = ngx_strlcasestrn(start, last, (u_char *) "max-age=", 8 - 1);
+ offset = 8;
+ }
if (p == NULL) {
return NGX_OK;
@@ -3968,7 +3974,7 @@ ngx_http_upstream_process_cache_control(
n = 0;
- for (p += 8; p < last; p++) {
+ for (p += offset; p < last; p++) {
if (*p == ',' || *p == ';' || *p == ' ') {
break;
}
More information about the nginx-devel
mailing list