From: Eric Covener Date: Mon, 25 Jan 2016 19:57:33 +0000 (+0000) Subject: better s-maxage support X-Git-Tag: 2.5.0-alpha~2281 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c9c90fca19862284b3c63cef710568a7cd80397f;p=apache better s-maxage support + *) mod_cache: Consider Cache-Control: s-maxage in expiration + calculations. [Eric Covener] + + *) mod_cache: Allow caching of responses with an Expires header + in the past that also has Cache-Control: max-age or s-maxage. + PR55156. [Eric Covener] git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1726675 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index f73f06c4b6..a6ad96a804 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,12 @@ -*- coding: utf-8 -*- Changes with Apache 2.5.0 + + *) mod_cache: Consider Cache-Control: s-maxage in expiration + calculations. [Eric Covener] + + *) mod_cache: Allow caching of responses with an Expires header + in the past that also has Cache-Control: max-age or s-maxage. + PR55156. [Eric Covener] *) ap_expr: expression support for variable HTTP2=on|off [Stefan Eissing] diff --git a/modules/cache/mod_cache.c b/modules/cache/mod_cache.c index 4f7f25a582..742bfcca5c 100644 --- a/modules/cache/mod_cache.c +++ b/modules/cache/mod_cache.c @@ -1041,9 +1041,12 @@ static apr_status_t cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in) /* if a broken Expires header is present, don't cache it */ reason = apr_pstrcat(p, "Broken expires header: ", exps, NULL); } - else if (!dconf->store_expired && exp != APR_DATE_BAD + else if (!control.s_maxage && !control.max_age + && !dconf->store_expired && exp != APR_DATE_BAD && exp < r->request_time) { - /* if a Expires header is in the past, don't cache it */ + /* if a Expires header is in the past, don't cache it + * Unless CC: s-maxage or max-age is present + */ reason = "Expires header already expired; not cacheable"; } else if (!dconf->store_expired && (control.must_revalidate @@ -1397,7 +1400,26 @@ static apr_status_t cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in) "replacing with now"); } + + /* CC has priority over Expires. */ + if (control.s_maxage || control.max_age) { + apr_int64_t x; + + x = control.s_maxage ? control.s_maxage_value : control.max_age_value; + x = x * MSEC_ONE_SEC; + + if (x < dconf->minex) { + x = dconf->minex; + } + if (x > dconf->maxex) { + x = dconf->maxex; + } + exp = date + x; + } + /* if no expiry date then + * if Cache-Control: s-maxage + * expiry date = date + smaxage * if Cache-Control: max-age * expiry date = date + max-age * else if lastmod @@ -1405,22 +1427,9 @@ static apr_status_t cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in) * else * expire date = date + defaultexpire */ - if (exp == APR_DATE_BAD) { - - if (control.max_age) { - apr_int64_t x; - x = control.max_age_value * MSEC_ONE_SEC; - - if (x < dconf->minex) { - x = dconf->minex; - } - if (x > dconf->maxex) { - x = dconf->maxex; - } - exp = date + x; - } - else if ((lastmod != APR_DATE_BAD) && (lastmod < date)) { + if (exp == APR_DATE_BAD) { + if ((lastmod != APR_DATE_BAD) && (lastmod < date)) { /* if lastmod == date then you get 0*conf->factor which results in * an expiration time of now. This causes some problems with * freshness calculations, so we choose the else path...