]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Implemented HttpHdrCc::s_maxage getters and setters and value-based "unset" state.
authorFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 21 Sep 2011 07:52:42 +0000 (09:52 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 21 Sep 2011 07:52:42 +0000 (09:52 +0200)
src/HttpHdrCc.cc
src/HttpHdrCc.h
src/HttpReply.cc
src/http.cc

index ff96e70c9a7d1f826eb2de8b4b2cdc78ade8193d..8fa7d803293beae5801701e3124a98bda45b483d 100644 (file)
@@ -178,8 +178,7 @@ HttpHdrCc::parse(const String & str)
 
             if (!p || !httpHeaderParseInt(p, &cc->s_maxage)) {
                 debugs(65, 2, "cc: invalid s-maxage specs near '" << item << "'");
-                cc->s_maxage = -1;
-                EBIT_CLR(cc->mask, type);
+                cc->setSMaxAge(S_MAXAGE_UNSET);
             }
 
             break;
@@ -248,7 +247,7 @@ httpHdrCcPackInto(const HttpHdrCc * cc, Packer * p)
                 packerPrintf(p, "=%d", (int) cc->getMaxAge());
 
             if (flag == CC_S_MAXAGE)
-                packerPrintf(p, "=%d", (int) cc->s_maxage);
+                packerPrintf(p, "=%d", (int) cc->getSMaxAge());
 
             if (flag == CC_MAX_STALE && cc->max_stale >= 0)
                 packerPrintf(p, "=%d", (int) cc->max_stale);
@@ -265,19 +264,6 @@ httpHdrCcPackInto(const HttpHdrCc * cc, Packer * p)
                      SQUIDSTRINGPRINT(cc->other));
 }
 
-void
-HttpHdrCc::setMaxAge(int max_age_)
-{
-
-    if (max_age_ >= 0) {
-        EBIT_SET(mask, CC_MAX_AGE);
-        max_age = max_age_;
-    } else {
-        EBIT_CLR(mask, CC_MAX_AGE);
-        max_age=MAX_AGE_UNSET;
-    }
-}
-
 void
 httpHdrCcUpdateStats(const HttpHdrCc * cc, StatHist * hist)
 {
@@ -302,9 +288,36 @@ httpHdrCcStatDumper(StoreEntry * sentry, int idx, double val, double size, int c
                           id, name, count, xdiv(count, dump_stat->ccParsedCount));
 }
 
+void
+HttpHdrCc::setMaxAge(int max_age_)
+{
+
+    if (max_age_ >= 0) {
+        EBIT_SET(mask, CC_MAX_AGE);
+        max_age = max_age_;
+    } else {
+        EBIT_CLR(mask, CC_MAX_AGE);
+        max_age=MAX_AGE_UNSET;
+    }
+}
+
 int32_t HttpHdrCc::getMaxAge() const
 {
     return max_age;
 }
 
+void HttpHdrCc::setSMaxAge(int32_t s_maxage)
+{
+       if (s_maxage >= 0) {
+               EBIT_SET(mask, CC_S_MAXAGE);
+               this->s_maxage=s_maxage;
+       } else {
+               this->s_maxage=S_MAXAGE_UNSET;
+               EBIT_CLR(mask, CC_S_MAXAGE);
+       }
+}
 
+int32_t HttpHdrCc::getSMaxAge() const
+{
+       return s_maxage;
+}
index 09b0fd190d9f20f0e17c2a433d7ee1a299a132eb..5519d8f2102fe32eceed3b5e215a335049255253 100644 (file)
@@ -45,9 +45,10 @@ class HttpHdrCc
 
 public:
        static const int32_t MAX_AGE_UNSET=-1; //max-age is unset
+       static const int32_t S_MAXAGE_UNSET=-1; //max-age is unset
 
     explicit HttpHdrCc() :
-            mask(0), max_age(MAX_AGE_UNSET), s_maxage(-1),
+            mask(0), max_age(MAX_AGE_UNSET), s_maxage(S_MAXAGE_UNSET),
             max_stale(-1), stale_if_error(0),
             min_fresh(-1) {}
 
@@ -57,13 +58,17 @@ public:
     void setMaxAge(int32_t max_age);
     int32_t getMaxAge() const;
 
+    void setSMaxAge(int32_t s_maxage);
+    int32_t getSMaxAge() const;
+
+
     MEMPROXY_CLASS(HttpHdrCc);
 
     int32_t mask;
 private:
     int32_t max_age;
-public:
     int32_t s_maxage;
+public:
     int32_t max_stale;
     int32_t stale_if_error;
     int32_t min_fresh;
index fb6ef2923844888a6dbf629820e36514607f146a..92d61ebc48dbe80b813a9e50b17385167f118c75 100644 (file)
@@ -331,8 +331,8 @@ HttpReply::hdrExpirationTime()
 
     if (cache_control) {
         if (date >= 0) {
-            if (cache_control->s_maxage >= 0)
-                return date + cache_control->s_maxage;
+            if (cache_control->getSMaxAge() != HttpHdrCc::S_MAXAGE_UNSET)
+                return date + cache_control->getSMaxAge();
 
             if (cache_control->getMaxAge() >= 0)
                 return date + cache_control->getMaxAge();
@@ -342,7 +342,7 @@ HttpReply::hdrExpirationTime()
              * header, but no Date for reference?
              */
 
-            if (cache_control->s_maxage >= 0)
+            if (cache_control->getSMaxAge()!=HttpHdrCc::S_MAXAGE_UNSET)
                 return squid_curtime;
 
             if (cache_control->getMaxAge() >= 0)
index a698a3eb71b78f028c3b35b73dd8e980fc35cb65..12c06b617f8966ec8338505d04762881f4382ac4 100644 (file)
@@ -928,7 +928,8 @@ no_cache:
     if (!ignoreCacheControl && rep->cache_control) {
         if (EBIT_TEST(rep->cache_control->mask, CC_PROXY_REVALIDATE) ||
                 EBIT_TEST(rep->cache_control->mask, CC_MUST_REVALIDATE) ||
-                EBIT_TEST(rep->cache_control->mask, CC_S_MAXAGE))
+                rep->cache_control->getSMaxAge() != HttpHdrCc::S_MAXAGE_UNSET
+                )
             EBIT_SET(entry->flags, ENTRY_REVALIDATE);
     }
 
@@ -1770,7 +1771,7 @@ HttpStateData::httpBuildRequestHeader(HttpRequest * request,
 #endif
 
         /* Add max-age only without no-cache */
-        if (!EBIT_TEST(cc->mask, CC_MAX_AGE) && !EBIT_TEST(cc->mask, CC_NO_CACHE)) {
+        if (cc->getMaxAge()==HttpHdrCc::MAX_AGE_UNSET && !EBIT_TEST(cc->mask, CC_NO_CACHE)) {
             const char *url =
                 entry ? entry->url() : urlCanonical(request);
             cc->setMaxAge(getMaxAge(url));