From 1ba0611afd42b0197a64558d2d0b74d681003690 Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Tue, 20 Sep 2011 23:35:03 +0200 Subject: [PATCH] Implemented full setter/getter structure for HttpHdrCc::max_age refactoring. --- src/HttpHdrCc.cc | 26 ++++++++++++++++++-------- src/HttpHdrCc.h | 20 ++++---------------- src/HttpReply.cc | 6 +++--- src/refresh.cc | 8 ++++---- 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/HttpHdrCc.cc b/src/HttpHdrCc.cc index 1fe637beb3..dd30b593dc 100644 --- a/src/HttpHdrCc.cc +++ b/src/HttpHdrCc.cc @@ -164,11 +164,12 @@ HttpHdrCc::parse(const String & str) switch (type) { case CC_MAX_AGE: - - if (!p || !httpHeaderParseInt(p, &cc->max_age)) { + int32_t ma; + if (!p || !httpHeaderParseInt(p, &ma)) { debugs(65, 2, "cc: invalid max-age specs near '" << item << "'"); - cc->max_age = -1; - EBIT_CLR(cc->mask, type); + cc->setMaxAge(-1); + } else { + cc->setMaxAge(ma); } break; @@ -244,7 +245,7 @@ httpHdrCcPackInto(const HttpHdrCc * cc, Packer * p) /* handle options with values */ if (flag == CC_MAX_AGE) - packerPrintf(p, "=%d", (int) cc->max_age); + packerPrintf(p, "=%d", (int) cc->getMaxAge()); if (flag == CC_S_MAXAGE) packerPrintf(p, "=%d", (int) cc->s_maxage); @@ -267,12 +268,14 @@ httpHdrCcPackInto(const HttpHdrCc * cc, Packer * p) void HttpHdrCc::setMaxAge(int max_age_) { - max_age = max_age_; - if (max_age_ >= 0) + if (max_age_ >= 0) { EBIT_SET(mask, CC_MAX_AGE); - else + max_age = max_age_; + } else { EBIT_CLR(mask, CC_MAX_AGE); + max_age=-1; + } } void @@ -298,3 +301,10 @@ httpHdrCcStatDumper(StoreEntry * sentry, int idx, double val, double size, int c storeAppendPrintf(sentry, "%2d\t %-20s\t %5d\t %6.2f\n", id, name, count, xdiv(count, dump_stat->ccParsedCount)); } + +int32_t HttpHdrCc::getMaxAge() const +{ + return max_age; +} + + diff --git a/src/HttpHdrCc.h b/src/HttpHdrCc.h index 81ee399bf6..b0571e1115 100644 --- a/src/HttpHdrCc.h +++ b/src/HttpHdrCc.h @@ -49,32 +49,20 @@ public: max_stale(-1), stale_if_error(0), min_fresh(-1) {} - /// reset to the after-default-construction state. void clear(); - - /**parse the supplied string filling in HttpHdrCc's fields. - * - * \note: internal structures are not cleaned-up beforehand. - * caller must explicitly clear() beforehand if he wants that - */ - bool parse(const String &s); - - /** set the max_age value - * - * \param max_age the new max age. Values <0 clear it. - */ + bool parse(const String & s); void setMaxAge(int32_t max_age); - + int32_t getMaxAge() const; MEMPROXY_CLASS(HttpHdrCc); - /// bit-mask for the various Cc directives, keyed on http_hdr_cc_type int32_t mask; +private: int32_t max_age; +public: int32_t s_maxage; int32_t max_stale; int32_t stale_if_error; int32_t min_fresh; - /// comma-separated string accumulating unknown Cache-control directives. String other; }; diff --git a/src/HttpReply.cc b/src/HttpReply.cc index 57d0449733..fb6ef29238 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -334,8 +334,8 @@ HttpReply::hdrExpirationTime() if (cache_control->s_maxage >= 0) return date + cache_control->s_maxage; - if (cache_control->max_age >= 0) - return date + cache_control->max_age; + if (cache_control->getMaxAge() >= 0) + return date + cache_control->getMaxAge(); } else { /* * Conservatively handle the case when we have a max-age @@ -345,7 +345,7 @@ HttpReply::hdrExpirationTime() if (cache_control->s_maxage >= 0) return squid_curtime; - if (cache_control->max_age >= 0) + if (cache_control->getMaxAge() >= 0) return squid_curtime; } } diff --git a/src/refresh.cc b/src/refresh.cc index af6acafb57..704eb3d81f 100644 --- a/src/refresh.cc +++ b/src/refresh.cc @@ -335,19 +335,19 @@ refreshCheck(const StoreEntry * entry, HttpRequest * request, time_t delta) #endif if (NULL != cc) { - if (cc->max_age > -1) { + if (cc->getMaxAge() >= 0) { #if USE_HTTP_VIOLATIONS - if (R->flags.ignore_reload && cc->max_age == 0) { + if (R->flags.ignore_reload && cc->getMaxAge() == 0) { debugs(22, 3, "refreshCheck: MAYBE: client-max-age = 0 and ignore-reload"); } else #endif { - if (cc->max_age == 0) { + if (cc->getMaxAge() == 0) { debugs(22, 3, "refreshCheck: YES: client-max-age = 0"); return STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE; } - if (age > cc->max_age) { + if (age > cc->getMaxAge()) { debugs(22, 3, "refreshCheck: YES: age > client-max-age"); return STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE; } -- 2.47.3