From: Francesco Chemolli Date: Thu, 29 Sep 2011 06:53:34 +0000 (+0200) Subject: Optimized HttpHdrCc::packInto and clarified its behaviour in comments X-Git-Tag: BumpSslServerFirst.take01~126^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c397963f33267ed9051eea7042cc1d72a1df8d91;p=thirdparty%2Fsquid.git Optimized HttpHdrCc::packInto and clarified its behaviour in comments Negative values to Cache-Control directives are now explicitly discarded Clarified documentation --- diff --git a/src/HttpHdrCc.cc b/src/HttpHdrCc.cc index d6c18e565c..74a86f1247 100644 --- a/src/HttpHdrCc.cc +++ b/src/HttpHdrCc.cc @@ -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; } diff --git a/src/HttpHdrCc.cci b/src/HttpHdrCc.cci index 1f239be1fa..17e69648f7 100644 --- a/src/HttpHdrCc.cci +++ b/src/HttpHdrCc.cci @@ -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 } diff --git a/src/HttpHdrCc.h b/src/HttpHdrCc.h index 5774c693a1..b31b2be313 100644 --- a/src/HttpHdrCc.h +++ b/src/HttpHdrCc.h @@ -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