]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Optimized HttpHdrCc::packInto and clarified its behaviour in comments
authorFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 29 Sep 2011 06:53:34 +0000 (08:53 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 29 Sep 2011 06:53:34 +0000 (08:53 +0200)
Negative values to Cache-Control directives are now explicitly discarded
Clarified documentation

src/HttpHdrCc.cc
src/HttpHdrCc.cci
src/HttpHdrCc.h

index d6c18e565c07daeda9540f9e6d5c971ec3783d7b..74a86f1247ff0856db98c5c72c557f8ec12c427b 100644 (file)
@@ -223,22 +223,30 @@ HttpHdrCc::packInto(Packer * p) const
     for (flag = CC_PUBLIC; flag < CC_ENUM_END; ++flag) {
         if (isSet(flag) && flag != CC_OTHER) {
 
-            /* print option name */
+            /* print option name for all options */
             packerPrintf(p, (pcount ? ", %s": "%s") , CcAttrs[flag].name);
 
-            /* handle options with values */
-
-            if (flag == CC_MAX_AGE)
+            /* for all options having values, "=value" after the name */
+            switch (flag) {
+            case CC_MAX_AGE:
                 packerPrintf(p, "=%d", (int) maxAge());
-
-            if (flag == CC_S_MAXAGE)
+                break;
+            case CC_S_MAXAGE:
                 packerPrintf(p, "=%d", (int) sMaxAge());
-
-            if (flag == CC_MAX_STALE && maxStale()!=MAX_STALE_ANY)
-                packerPrintf(p, "=%d", (int) maxStale());
-
-            if (flag == CC_MIN_FRESH)
+                break;
+            case CC_MAX_STALE:
+                /* max-stale's value is optional.
+                  If we didn't receive it, don't send it */
+                if (maxStale()!=MAX_STALE_ANY)
+                    packerPrintf(p, "=%d", (int) maxStale());
+                break;
+            case CC_MIN_FRESH:
                 packerPrintf(p, "=%d", (int) minFresh());
+                break;
+            default:
+                /* do nothing, directive was already printed */
+                break;
+            }
 
             ++pcount;
         }
index 1f239be1fa70e595428fedbb3473a4c2d43f65fb..17e69648f743f234921cb514fb8fe16c6a995b17 100644 (file)
@@ -51,9 +51,11 @@ void
 HttpHdrCc::setValue(int32_t &value, int32_t new_value, http_hdr_cc_type hdr, bool setting)
 {
     if (setting) {
-        if (new_value < 0)
-            debugs(65,3,HERE << "rejecting negative Cache-Control directive " << hdr
+        if (new_value < 0) {
+            debugs(65,3,HERE << "rejecting negative-value Cache-Control directive " << hdr
                 << " value " << new_value );
+            return;
+        }
     } else {
         new_value=-1; //rely on the convention that "unknown" is -1
     }
index 5774c693a15d56da3a2ae8a0566d126fcffc9e4f..b31b2be3136ff5dfe5882f49a224e91054eefeee 100644 (file)
@@ -47,7 +47,9 @@ public:
        static const int32_t MAX_AGE_UNKNOWN=-1; //max-age is unset
        static const int32_t S_MAXAGE_UNKNOWN=-1; //s-maxage is unset
        static const int32_t MAX_STALE_UNKNOWN=-1; //max-stale is unset
-       static const int32_t MAX_STALE_ANY=0x7fffffff; //max-stale is set to no value, meaning "any"
+       ///used to mark a valueless Cache-Control: max-stale directive, which instructs
+       /// us to treat responses of any age as fresh
+       static const int32_t MAX_STALE_ANY=0x7fffffff;
        static const int32_t STALE_IF_ERROR_UNKNOWN=-1; //stale_if_error is unset
        static const int32_t MIN_FRESH_UNKNOWN=-1; //min_fresh is unset