]> granicus.if.org Git - apache/commitdiff
mod_cache: Let Cache-Control max-age set the expiration of the cached
authorJustin Erenkrantz <jerenkrantz@apache.org>
Thu, 17 May 2007 18:25:13 +0000 (18:25 +0000)
committerJustin Erenkrantz <jerenkrantz@apache.org>
Thu, 17 May 2007 18:25:13 +0000 (18:25 +0000)
representation if Expires is not set.

* modules/cache/mod_cache.c
  (cache_save_filter): If Cache-Control max-age is set and Expires isn't,
  let that value control our expiration.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@539063 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
modules/cache/mod_cache.c

diff --git a/CHANGES b/CHANGES
index 7835948d0903ff458b016d26adb1d40d90b10670..f8e06aa5cbbbdda7af0e66f19da5a932eb1a930f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,9 @@
 Changes with Apache 2.3.0
   [Remove entries to the current 2.0 and 2.2 section below, when backported]
 
+  *) mod_cache: Let Cache-Control max-age set the expiration of the cached
+     representation if Expires is not set.  [Justin Erenkrantz]
+
   *) mod_disk_cache: Allow Vary'd responses to be refreshed properly.
      [Justin Erenkrantz]
 
index a2f4f3ef45adb0f9bfa465b68729f56ba2cd5472..6f4170a36bd707ac3184069eff7d471d3be887b2 100644 (file)
@@ -701,19 +701,42 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
     }
 
     /* if no expiry date then
-     *   if lastmod
+     *   if Cache-Control: max-age
+     *      expiry date = date + max-age
+     *   else if lastmod
      *      expiry date = date + min((date - lastmod) * factor, maxexpire)
      *   else
      *      expire date = date + defaultexpire
      */
     if (exp == APR_DATE_BAD) {
         char expire_hdr[APR_RFC822_DATE_LEN];
+        char *max_age_val;
 
-        /* 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...
-         */
-        if ((lastmod != APR_DATE_BAD) && (lastmod < date)) {
+        if (ap_cache_liststr(r->pool, cc_out, "max-age", &max_age_val) &&
+            max_age_val != NULL) {
+            apr_int64_t x;
+
+            errno = 0;
+            x = apr_atoi64(max_age_val);
+            if (errno) {
+                x = conf->defex;
+            }
+            else {
+                x = x * MSEC_ONE_SEC;
+            }
+            if (x < conf->minex) {
+                x = conf->minex;
+            }
+            if (x > conf->maxex) {
+                x = conf->maxex;
+            }
+            exp = date + x;
+        }
+        else 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...
+             */
             apr_time_t x = (apr_time_t) ((date - lastmod) * conf->factor);
 
             if (x < conf->minex) {