]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
implemented getters and setters for HttpHdrCc::max_stale
authorFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 22 Sep 2011 13:59:53 +0000 (15:59 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 22 Sep 2011 13:59:53 +0000 (15:59 +0200)
src/HttpHdrCc.cc
src/HttpHdrCc.h
src/refresh.cc

index 8fa7d803293beae5801701e3124a98bda45b483d..a29388b9bb29a61583afd1255382b7067d2a158a 100644 (file)
@@ -187,7 +187,7 @@ HttpHdrCc::parse(const String & str)
 
             if (!p || !httpHeaderParseInt(p, &cc->max_stale)) {
                 debugs(65, 2, "cc: max-stale directive is valid without value");
-                cc->max_stale = -1;
+                cc->setMaxStale(MAX_STALE_ALWAYS);
             }
 
             break;
@@ -249,8 +249,8 @@ httpHdrCcPackInto(const HttpHdrCc * cc, Packer * p)
             if (flag == 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);
+            if (flag == CC_MAX_STALE && cc->getMaxStale() >= 0)
+                packerPrintf(p, "=%d", (int) cc->getMaxStale());
 
             if (flag == CC_MIN_FRESH)
                 packerPrintf(p, "=%d", (int) cc->min_fresh);
@@ -312,8 +312,8 @@ void HttpHdrCc::setSMaxAge(int32_t s_maxage)
                EBIT_SET(mask, CC_S_MAXAGE);
                this->s_maxage=s_maxage;
        } else {
-               this->s_maxage=S_MAXAGE_UNSET;
                EBIT_CLR(mask, CC_S_MAXAGE);
+               this->s_maxage=S_MAXAGE_UNSET;
        }
 }
 
@@ -321,3 +321,18 @@ int32_t HttpHdrCc::getSMaxAge() const
 {
        return s_maxage;
 }
+
+void HttpHdrCc::setMaxStale(int32_t max_stale)
+{
+       if (max_stale>=0 || max_stale==MAX_STALE_ALWAYS) {
+               EBIT_SET(mask,CC_MAX_STALE);
+               this->max_stale=max_stale;
+       } else {
+               EBIT_CLR(mask, CC_MAX_STALE);
+               this->max_stale=MAX_STALE_UNSET;
+       }
+}
+int32_t HttpHdrCc::getMaxStale() const
+{
+       return max_stale;
+}
index a952b247cc2caedca0729a2b46294988d8f78238..768058f6ebadcfa243d0ae798497626d1363f3b0 100644 (file)
@@ -45,11 +45,13 @@ 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
+       static const int32_t S_MAXAGE_UNSET=-1; //s-maxage is unset
+       static const int32_t MAX_STALE_UNSET=-1; //max-stale is unset
+       static const int32_t MAX_STALE_ALWAYS=-2; //max-stale is set to no value
 
     explicit HttpHdrCc() :
             mask(0), max_age(MAX_AGE_UNSET), s_maxage(S_MAXAGE_UNSET),
-            max_stale(-1), stale_if_error(0),
+            max_stale(MAX_STALE_UNSET), stale_if_error(0),
             min_fresh(-1) {}
 
     void clear();
@@ -61,6 +63,8 @@ public:
     void setSMaxAge(int32_t s_maxage);
     int32_t getSMaxAge() const;
 
+    void setMaxStale(int32_t max_stale);
+    int32_t getMaxStale() const;
 
     MEMPROXY_CLASS(HttpHdrCc);
 
@@ -68,8 +72,8 @@ public:
 private:
     int32_t max_age;
     int32_t s_maxage;
-public:
     int32_t max_stale;
+public:
     int32_t stale_if_error;
     int32_t min_fresh;
     String other;
index 704eb3d81f5cf4f5a4ac27fc083e0dc3240049a1..924b253d47cfb75e9df1e9628fc34cdffb2c3d08 100644 (file)
@@ -354,12 +354,12 @@ refreshCheck(const StoreEntry * entry, HttpRequest * request, time_t delta)
                 }
             }
 
-            if (EBIT_TEST(cc->mask, CC_MAX_STALE) && staleness > -1) {
-                if (cc->max_stale < 0) {
+            if (cc->getMaxStale()>=0 && staleness > -1) {
+                if (cc->getMaxStale()==HttpHdrCc::MAX_STALE_ALWAYS) {
                     /* max-stale directive without a value */
                     debugs(22, 3, "refreshCheck: NO: max-stale wildcard");
                     return FRESH_REQUEST_MAX_STALE_ALL;
-                } else if (staleness < cc->max_stale) {
+                } else if (staleness < cc->getMaxStale()) {
                     debugs(22, 3, "refreshCheck: NO: staleness < max-stale");
                     return FRESH_REQUEST_MAX_STALE_VALUE;
                 }