From 838924d06e104450e2770203da8f88aeb6f4efa7 Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Wed, 21 Sep 2011 09:52:42 +0200 Subject: [PATCH] Implemented HttpHdrCc::s_maxage getters and setters and value-based "unset" state. --- src/HttpHdrCc.cc | 45 +++++++++++++++++++++++++++++---------------- src/HttpHdrCc.h | 9 +++++++-- src/HttpReply.cc | 6 +++--- src/http.cc | 5 +++-- 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/HttpHdrCc.cc b/src/HttpHdrCc.cc index ff96e70c9a..8fa7d80329 100644 --- a/src/HttpHdrCc.cc +++ b/src/HttpHdrCc.cc @@ -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; +} diff --git a/src/HttpHdrCc.h b/src/HttpHdrCc.h index 09b0fd190d..5519d8f210 100644 --- a/src/HttpHdrCc.h +++ b/src/HttpHdrCc.h @@ -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; diff --git a/src/HttpReply.cc b/src/HttpReply.cc index fb6ef29238..92d61ebc48 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -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) diff --git a/src/http.cc b/src/http.cc index a698a3eb71..12c06b617f 100644 --- a/src/http.cc +++ b/src/http.cc @@ -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)); -- 2.47.2