]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Alex Rousskov <rousskov@measurement-factory.com>
authorAmos Jeffries <amosjeffries@squid-cache.org>
Sat, 23 Oct 2010 13:41:01 +0000 (07:41 -0600)
committerAmos Jeffries <amosjeffries@squid-cache.org>
Sat, 23 Oct 2010 13:41:01 +0000 (07:41 -0600)
HTTP Compliance: support requests with Cache-Control: min-fresh.

Added min-fresh directive support for Cache-Control header. The directive is
handled in refreshCheck() by incrementing age and check_time by min-fresh
value.

Co-Advisor test case:
    test_case/rfc2616/ccReqDirMsg-min-fresh-obey

src/HttpHdrCc.cc
src/enums.h
src/refresh.cc
src/structs.h

index cc9356bad015dc595a0d1433877a104711025944..502ba8e864320ef7341fa36cfa0e1e5f5a521725 100644 (file)
@@ -51,6 +51,7 @@ static const HttpHeaderFieldAttrs CcAttrs[CC_ENUM_END] = {
     {"max-age", (http_hdr_type)CC_MAX_AGE},
     {"s-maxage", (http_hdr_type)CC_S_MAXAGE},
     {"max-stale", (http_hdr_type)CC_MAX_STALE},
+    {"min-fresh", (http_hdr_type)CC_MIN_FRESH},
     {"Other,", (http_hdr_type)CC_OTHER}        /* ',' will protect from matches */
 };
 
@@ -89,7 +90,7 @@ HttpHdrCc *
 httpHdrCcCreate(void)
 {
     HttpHdrCc *cc = (HttpHdrCc *)memAllocate(MEM_HTTP_HDR_CC);
-    cc->max_age = cc->s_maxage = cc->max_stale = -1;
+    cc->max_age = cc->s_maxage = cc->max_stale = cc->min_fresh = -1;
     return cc;
 }
 
@@ -181,6 +182,16 @@ httpHdrCcParseInit(HttpHdrCc * cc, const String * str)
 
             break;
 
+        case CC_MIN_FRESH:
+
+            if (!p || !httpHeaderParseInt(p, &cc->min_fresh)) {
+                debugs(65, 2, "cc: invalid min-fresh specs near '" << item << "'");
+                cc->min_fresh = -1;
+                EBIT_CLR(cc->mask, type);
+            }
+
+            break;
+
         case CC_OTHER:
 
             if (cc->other.size())
@@ -220,6 +231,7 @@ httpHdrCcDup(const HttpHdrCc * cc)
     dup->max_age = cc->max_age;
     dup->s_maxage = cc->s_maxage;
     dup->max_stale = cc->max_stale;
+    dup->min_fresh = cc->min_fresh;
     return dup;
 }
 
@@ -248,6 +260,9 @@ httpHdrCcPackInto(const HttpHdrCc * cc, Packer * p)
             if (flag == CC_MAX_STALE && cc->max_stale >= 0)
                 packerPrintf(p, "=%d", (int) cc->max_stale);
 
+            if (flag == CC_MIN_FRESH)
+                packerPrintf(p, "=%d", (int) cc->min_fresh);
+
             pcount++;
         }
     }
index cb1f5f0b3985aff9fadfa492b08fd4cb0b1432e7..f3b4bfde3357a1a55eda774fe5e26d986c7e9f55 100644 (file)
@@ -144,6 +144,7 @@ typedef enum {
     CC_MAX_AGE,
     CC_S_MAXAGE,
     CC_MAX_STALE,
+    CC_MIN_FRESH,
     CC_ONLY_IF_CACHED,
     CC_OTHER,
     CC_ENUM_END
index dc39714f72a6833c0833b480009ad063b6884ade..a61e5d820d1ce8163543e818f186526fb148f363 100644 (file)
@@ -254,23 +254,35 @@ refreshCheck(const StoreEntry * entry, HttpRequest * request, time_t delta)
     if (NULL == R)
         R = &DefaultRefresh;
 
-    memset(&sf, '\0', sizeof(sf));
-
-    staleness = refreshStaleness(entry, check_time, age, R, &sf);
-
-    debugs(22, 3, "Staleness = " << staleness);
-
     debugs(22, 3, "refreshCheck: Matched '" << R->pattern << " " <<
            (int) R->min << " " << (int) (100.0 * R->pct) << "%% " <<
            (int) R->max << "'");
 
-
-    debugs(22, 3, "refreshCheck: age = " << age);
+    debugs(22, 3, "\tage:\t" << age);
 
     debugs(22, 3, "\tcheck_time:\t" << mkrfc1123(check_time));
 
     debugs(22, 3, "\tentry->timestamp:\t" << mkrfc1123(entry->timestamp));
 
+    if (request && !request->flags.ignore_cc) {
+        const HttpHdrCc *const cc = request->cache_control;
+        if (cc && cc->min_fresh > 0) {
+            debugs(22, 3, "\tage + min-fresh:\t" << age << " + " <<
+                   cc->min_fresh << " = " << age + cc->min_fresh);
+            debugs(22, 3, "\tcheck_time + min-fresh:\t" << check_time << " + "
+                   << cc->min_fresh << " = " <<
+                   mkrfc1123(check_time + cc->min_fresh));
+            age += cc->min_fresh;
+            check_time += cc->min_fresh;
+        }
+    }
+
+    memset(&sf, '\0', sizeof(sf));
+
+    staleness = refreshStaleness(entry, check_time, age, R, &sf);
+
+    debugs(22, 3, "Staleness = " << staleness);
+
     if (EBIT_TEST(entry->flags, ENTRY_REVALIDATE) && staleness > -1
 #if HTTP_VIOLATIONS
             && !R->flags.ignore_must_revalidate
index 6e8bbc24e335e5f7b208d12e85db315d540b67bc..05e61a2b5e173c9f18a4cfb5d3d375634e1de508 100644 (file)
@@ -723,6 +723,7 @@ public:
     int max_age;
     int s_maxage;
     int max_stale;
+    int min_fresh;
     String other;
 };