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;
}
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
}
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