Skip to content

Commit

Permalink
Cache: add support for Cache-Control's s-maxage response directive.
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Sikora <[email protected]>
  • Loading branch information
PiotrSikora committed Nov 19, 2014
1 parent 1b79cb2 commit 3ecac9e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/http/ngx_http_upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -3934,7 +3934,7 @@ ngx_http_upstream_process_cache_control(ngx_http_request_t *r,

#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) {
Expand All @@ -3949,26 +3949,32 @@ ngx_http_upstream_process_cache_control(ngx_http_request_t *r,
return NGX_OK;
}

p = h->value.data;
last = p + h->value.len;
start = h->value.data;
last = start + 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)
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;
}

n = 0;

for (p += 8; p < last; p++) {
for (p += offset; p < last; p++) {
if (*p == ',' || *p == ';' || *p == ' ') {
break;
}
Expand Down

0 comments on commit 3ecac9e

Please sign in to comment.