}
}
- /* post-processing, including special cases */
+ /* special-case-parsing and attribute-setting */
switch (type) {
case CC_MAX_AGE:
int32_t ma;
if (!p || !httpHeaderParseInt(p, &ma)) {
debugs(65, 2, "cc: invalid max-age specs near '" << item << "'");
- maxAge(MAX_AGE_UNKNOWN);
+ clearMaxAge();
} else {
maxAge(ma);
}
-
break;
case CC_S_MAXAGE:
-
if (!p || !httpHeaderParseInt(p, &s_maxage)) {
debugs(65, 2, "cc: invalid s-maxage specs near '" << item << "'");
- sMaxAge(S_MAXAGE_UNKNOWN);
+ clearSMaxAge();
}
-
break;
case CC_MAX_STALE:
-
if (!p || !httpHeaderParseInt(p, &max_stale)) {
debugs(65, 2, "cc: max-stale directive is valid without value");
- setMaxStale(MAX_STALE_ALWAYS);
+ maxStale(MAX_STALE_ALWAYS);
}
-
break;
case CC_MIN_FRESH:
-
if (!p || !httpHeaderParseInt(p, &min_fresh)) {
debugs(65, 2, "cc: invalid min-fresh specs near '" << item << "'");
- setMinFresh(MIN_FRESH_UNKNOWN);
+ clearMinFresh();
}
-
break;
case CC_STALE_IF_ERROR:
if (!p || !httpHeaderParseInt(p, &stale_if_error)) {
debugs(65, 2, "cc: invalid stale-if-error specs near '" << item << "'");
- setStaleIfError(STALE_IF_ERROR_UNKNOWN);
+ clearStaleIfError();
}
break;
- case CC_OTHER:
+ case CC_PUBLIC: Public(true); break;
+ case CC_PRIVATE: Private(true); break;
+ case CC_NO_CACHE: noCache(true); break;
+ case CC_NO_STORE: noStore(true); break;
+ case CC_NO_TRANSFORM: noTransform(true); break;
+ case CC_MUST_REVALIDATE: mustRevalidate(true); break;
+ case CC_PROXY_REVALIDATE: proxyRevalidate(true); break;
+ case CC_ONLY_IF_CACHED: onlyIfCached(true); break;
+ case CC_OTHER:
if (other.size())
other.append(", ");
other.append(item, ilen);
-
break;
default:
-
- set(type);
/* note that we ignore most of '=' specs (RFCVIOLATION) */
break;
}
}
void
-httpHdrCcPackInto(const HttpHdrCc * cc, Packer * p)
+HttpHdrCc::packInto(Packer * p) const
{
http_hdr_cc_type flag;
int pcount = 0;
- assert(cc && p);
+ assert(p);
for (flag = CC_PUBLIC; flag < CC_ENUM_END; ++flag) {
- if (cc->isSet(flag) && flag != CC_OTHER) {
+ if (isSet(flag) && flag != CC_OTHER) {
/* print option name */
packerPrintf(p, (pcount ? ", %s": "%s") , CcAttrs[flag].name);
/* handle options with values */
if (flag == CC_MAX_AGE)
- packerPrintf(p, "=%d", (int) cc->maxAge());
+ packerPrintf(p, "=%d", (int) maxAge());
if (flag == CC_S_MAXAGE)
- packerPrintf(p, "=%d", (int) cc->sMaxAge());
+ packerPrintf(p, "=%d", (int) sMaxAge());
- if (flag == CC_MAX_STALE && cc->getMaxStale() >= 0)
- packerPrintf(p, "=%d", (int) cc->getMaxStale());
+ if (flag == CC_MAX_STALE && maxStale()!=MAX_STALE_ALWAYS)
+ packerPrintf(p, "=%d", (int) maxStale());
if (flag == CC_MIN_FRESH)
- packerPrintf(p, "=%d", (int) cc->getMinFresh());
+ packerPrintf(p, "=%d", (int) minFresh());
++pcount;
}
}
- if (cc->other.size() != 0)
+ if (other.size() != 0)
packerPrintf(p, (pcount ? ", " SQUIDSTRINGPH : SQUIDSTRINGPH),
- SQUIDSTRINGPRINT(cc->other));
+ SQUIDSTRINGPRINT(other));
}
void
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
*
*/
-
-
-void
-HttpHdrCc::sMaxAge(int32_t s_maxage)
-{
- if (s_maxage>=0) {
- setMask(CC_S_MAXAGE);
- this->s_maxage=s_maxage;
- } else {
- setMask(CC_S_MAXAGE,false);
- this->s_maxage=S_MAXAGE_UNKNOWN;
- }
-}
-
-int32_t
-HttpHdrCc::sMaxAge() const
-{
- return s_maxage;
-}
-
-void
-HttpHdrCc::setMaxStale(int32_t max_stale)
-{
- if (max_stale>=0 || max_stale==MAX_STALE_ALWAYS) {
- setMask(CC_MAX_STALE);
- this->max_stale=max_stale;
- } else {
- setMask(CC_MAX_STALE,false);
- this->max_stale=MAX_STALE_UNKNOWN;
- }
-}
-int32_t
-HttpHdrCc::getMaxStale() const
-{
- return max_stale;
-}
-
-void
-HttpHdrCc::setStaleIfError(int32_t stale_if_error)
-{
- if (stale_if_error >= 0) {
- setMask(CC_STALE_IF_ERROR);
- this->stale_if_error=stale_if_error;
- } else {
- setMask(CC_STALE_IF_ERROR,false);
- this->stale_if_error=STALE_IF_ERROR_UNKNOWN;
- }
-}
-
-int32_t
-HttpHdrCc::getStaleIfError() const
-{
- return stale_if_error;
-}
-
-void
-HttpHdrCc::setMinFresh(int32_t min_fresh)
-{
- if (min_fresh >= 0) {
- setMask(CC_MIN_FRESH);
- this->min_fresh=min_fresh;
- } else {
- setMask(CC_MIN_FRESH,false);
- this->min_fresh=MIN_FRESH_UNKNOWN;
- }
-}
-
-int32_t
-HttpHdrCc::getMinFresh() const
-{
- return min_fresh;
-}
-
bool
HttpHdrCc::isSet(http_hdr_cc_type id) const
{
return EBIT_TEST(mask,id);
}
-void
-HttpHdrCc::set(http_hdr_cc_type id, bool newval)
-{
- assert(id>=CC_PUBLIC && id < CC_ENUM_END);
- assert(id!=CC_MAX_AGE && id != CC_S_MAXAGE &&
- id != CC_MAX_STALE && id != CC_STALE_IF_ERROR &&
- id != CC_MIN_FRESH);
- setMask(id,newval);
-}
-
void
HttpHdrCc::setMask(http_hdr_cc_type id, bool newval)
{
/// parse a header-string and fill in appropriate values.
bool parse(const String & s);
- //manipulation for Cache-Control: XXX header
- //inline bool haveXXX() const {return isSet();}
- //inline bool XXX() const {return isSet();}
- //inline void XXX(bool newval) {setMask(,newval);}
- //inline void clearXXX() {setMask(,false);}
-
//manipulation for Cache-Control: public header
inline bool havePublic() const {return isSet(CC_PUBLIC);}
- inline bool getPublic() const {return isSet(CC_PUBLIC);}
- inline void setPublic(bool newval) {setMask(CC_PUBLIC,newval);}
+ inline bool Public() const {return isSet(CC_PUBLIC);}
+ inline void Public(bool newval) {setMask(CC_PUBLIC,newval);}
inline void clearPublic() {setMask(CC_PUBLIC,false);}
//manipulation for Cache-Control: private header
inline bool havePrivate() const {return isSet(CC_PRIVATE);}
- inline bool getPrivate() const {return isSet(CC_PRIVATE);}
- inline void setPrivate(bool newval) {setMask(CC_PRIVATE,newval);}
+ inline bool Private() const {return isSet(CC_PRIVATE);}
+ inline void Private(bool newval) {setMask(CC_PRIVATE,newval);}
inline void clearPrivate() {setMask(CC_PRIVATE,false);}
//manipulation for Cache-Control: no-cache header
//manipulation for Cache-Control: max-age header
inline bool haveMaxAge() const {return isSet(CC_MAX_AGE);}
inline int32_t maxAge() const { return max_age;}
- inline void maxAge(int32_t max_age) {this->max_age = max_age; setMask(CC_MAX_AGE); }
+ inline void maxAge(int32_t newval) {if (newval < 0) return; max_age = newval; setMask(CC_MAX_AGE); }
inline void clearMaxAge() {max_age=MAX_AGE_UNKNOWN; setMask(CC_MAX_AGE,false);}
+ //manipulation for Cache-Control: s-maxage header
+ inline bool haveSMaxAge() const {return isSet(CC_S_MAXAGE);}
+ inline int32_t sMaxAge() const { return s_maxage;}
+ inline void sMaxAge(int32_t newval) {if (newval < 0) return; s_maxage = newval; setMask(CC_S_MAXAGE); }
+ inline void clearSMaxAge() {s_maxage=MAX_AGE_UNKNOWN; setMask(CC_S_MAXAGE,false);}
+
+ //manipulation for Cache-Control: max-stale header
+ inline bool haveMaxStale() const {return isSet(CC_MAX_STALE);}
+ inline int32_t maxStale() const { return max_stale;}
+ // max-stale has a special value (MAX_STALE_ALWAYS) which correspond to having
+ // the directive without a numeric specification, and directs to consider the object
+ // as always-expired.
+ inline void maxStale(int32_t newval) {
+ if (newval < 0 && newval != CC_MAX_STALE) return;
+ max_stale = newval; setMask(CC_MAX_STALE); }
+ inline void clearMaxStale() {max_stale=MAX_STALE_UNKNOWN; setMask(CC_MAX_STALE,false);}
+
+ //manipulation for Cache-Control:min-fresh header
+ inline bool haveMinFresh() const {return isSet(CC_MIN_FRESH);}
+ inline int32_t minFresh() const { return min_fresh;}
+ inline void minFresh(int32_t newval) {if (newval < 0) return; min_fresh = newval; setMask(CC_MIN_FRESH); }
+ inline void clearMinFresh() {min_fresh=MIN_FRESH_UNKNOWN; setMask(CC_MIN_FRESH,false);}
+
+ //manipulation for Cache-Control: only-if-cached header
+ inline bool haveOnlyIfCached() const {return isSet(CC_ONLY_IF_CACHED);}
+ inline bool onlyIfCached() const {return isSet(CC_ONLY_IF_CACHED);}
+ inline void onlyIfCached(bool newval) {setMask(CC_ONLY_IF_CACHED,newval);}
+ inline void clearOnlyIfCached() {setMask(CC_ONLY_IF_CACHED,false);}
+
+ //manipulation for Cache-Control: stale-if-error header
+ inline bool haveStaleIfError() const {return isSet(CC_STALE_IF_ERROR);}
+ inline int32_t staleIfError() const { return stale_if_error;}
+ inline void staleIfError(int32_t newval) {if (newval < 0) return; stale_if_error = newval; setMask(CC_STALE_IF_ERROR); }
+ inline void clearStaleIfError() {stale_if_error=STALE_IF_ERROR_UNKNOWN; setMask(CC_STALE_IF_ERROR,false);}
- /// s-maxage setter. Clear by setting to S_MAXAGE_UNKNOWN
- _SQUID_INLINE_ void sMaxAge(int32_t s_maxage);
- _SQUID_INLINE_ int32_t sMaxAge() const;
-
- /// max-stale setter. Clear by setting to MAX_STALE_UNKNOWN
- _SQUID_INLINE_ void setMaxStale(int32_t max_stale);
- _SQUID_INLINE_ int32_t getMaxStale() const;
-
- /// stale-if-error setter. Clear by setting to STALE_IF_ERROR_UNKNOWN
- _SQUID_INLINE_ void setStaleIfError(int32_t stale_if_error);
- _SQUID_INLINE_ int32_t getStaleIfError() const;
-
- /// min-fresh setter. Clear by setting to MIN_FRESH_UNKNOWN
- _SQUID_INLINE_ void setMinFresh(int32_t min_fresh);
- _SQUID_INLINE_ int32_t getMinFresh() const;
-
- /// set an attribute value or clear it (by supplying false as the second argument)
- _SQUID_INLINE_ void set(http_hdr_cc_type id, bool newval=true);
/// check whether the attribute value supplied by id is set
_SQUID_INLINE_ bool isSet(http_hdr_cc_type id) const;
+ void packInto(Packer * p) const;
+
MEMPROXY_CLASS(HttpHdrCc);
/** bit-mask representing what header values are set among those
/* pack into mb */
mb.init();
packerToMemInit(&p, &mb);
- httpHdrCcPackInto(cc, &p);
+ cc->packInto(&p);
/* put */
addEntry(new HttpHeaderEntry(HDR_CACHE_CONTROL, NULL, mb.buf));
/* cleanup */
if (cache_control) {
if (date >= 0) {
- if (cache_control->sMaxAge() != HttpHdrCc::S_MAXAGE_UNKNOWN)
+ if (cache_control->haveSMaxAge())
return date + cache_control->sMaxAge();
- if (cache_control->isSet(CC_MAX_AGE))
+ if (cache_control->haveMaxAge())
return date + cache_control->maxAge();
} else {
/*
* header, but no Date for reference?
*/
- if (cache_control->sMaxAge() != HttpHdrCc::S_MAXAGE_UNKNOWN)
+ if (cache_control->haveSMaxAge())
return squid_curtime;
- if (cache_control->isSet(CC_MAX_AGE))
+ if (cache_control->haveMaxAge())
return squid_curtime;
}
}
{
assert(request);
return request->cache_control &&
- request->cache_control->isSet(CC_ONLY_IF_CACHED);
+ request->cache_control->onlyIfCached();
}
/*
}
if (request->cache_control)
- if (request->cache_control->isSet(CC_NO_CACHE))
+ if (request->cache_control->noCache())
no_cache++;
/*
// RFC 2616: do not cache replies to responses with no-store CC directive
if (request && request->cache_control &&
- request->cache_control->isSet(CC_NO_STORE) &&
+ request->cache_control->noStore() &&
!REFRESH_OVERRIDE(ignore_no_store))
return 0;
if (!ignoreCacheControl && request->cache_control != NULL) {
const HttpHdrCc* cc=request->cache_control;
- if (cc->isSet(CC_PRIVATE)) {
+ if (cc->Private()) {
if (!REFRESH_OVERRIDE(ignore_private))
return 0;
}
- if (cc->isSet(CC_NO_CACHE)) {
+ if (cc->noCache()) {
if (!REFRESH_OVERRIDE(ignore_no_cache))
return 0;
}
- if (cc->isSet(CC_NO_STORE)) {
+ if (cc->noStore()) {
if (!REFRESH_OVERRIDE(ignore_no_store))
return 0;
}
* RFC 2068, sec 14.9.4
*/
- if (!request->cache_control->isSet(CC_PUBLIC)) {
+ if (!request->cache_control->Public()) {
if (!REFRESH_OVERRIDE(ignore_auth))
return 0;
}
no_cache:
if (!ignoreCacheControl && rep->cache_control) {
- if (rep->cache_control->isSet(CC_PROXY_REVALIDATE) ||
- rep->cache_control->isSet(CC_MUST_REVALIDATE) ||
- rep->cache_control->sMaxAge() != HttpHdrCc::S_MAXAGE_UNKNOWN
+ if (rep->cache_control->proxyRevalidate() ||
+ rep->cache_control->mustRevalidate() ||
+ rep->cache_control->haveSMaxAge()
)
EBIT_SET(entry->flags, ENTRY_REVALIDATE);
}
#endif
/* Add max-age only without no-cache */
- if (cc->isSet(CC_MAX_AGE) && !cc->isSet(CC_NO_CACHE)) {
+ if (cc->haveMaxAge() && !cc->noCache()) {
const char *url =
entry ? entry->url() : urlCanonical(request);
cc->maxAge(getMaxAge(url));
/* Enforce sibling relations */
if (flags.only_if_cached)
- cc->set(CC_ONLY_IF_CACHED);
+ cc->onlyIfCached(true);
hdr_out->putCc(cc);
/* Http Cache Control Header Field */
SQUIDCEXTERN void httpHdrCcInitModule(void);
SQUIDCEXTERN void httpHdrCcCleanModule(void);
-SQUIDCEXTERN void httpHdrCcPackInto(const HttpHdrCc * cc, Packer * p);
SQUIDCEXTERN void httpHdrCcUpdateStats(const HttpHdrCc * cc, StatHist * hist);
void httpHdrCcStatDumper(StoreEntry * sentry, int idx, double val, double size, int count);
if (request && !request->flags.ignore_cc) {
const HttpHdrCc *const cc = request->cache_control;
- if (cc && cc->getMinFresh()!=HttpHdrCc::MIN_FRESH_UNKNOWN) {
- const int32_t minFresh=cc->getMinFresh();
+ if (cc && cc->haveMinFresh()) {
+ const int32_t minFresh=cc->minFresh();
debugs(22, 3, "\tage + min-fresh:\t" << age << " + " <<
minFresh << " = " << age + minFresh);
debugs(22, 3, "\tcheck_time + min-fresh:\t" << check_time << " + "
// stale-if-error requires any failure be passed thru when its period is over.
if (request && entry->mem_obj && entry->mem_obj->getReply() && entry->mem_obj->getReply()->cache_control &&
- entry->mem_obj->getReply()->cache_control->getStaleIfError() != HttpHdrCc::STALE_IF_ERROR_UNKNOWN &&
- entry->mem_obj->getReply()->cache_control->getStaleIfError() < staleness) {
+ entry->mem_obj->getReply()->cache_control->haveStaleIfError() &&
+ entry->mem_obj->getReply()->cache_control->staleIfError() < staleness) {
debugs(22, 3, "refreshCheck: stale-if-error period expired.");
request->flags.fail_on_validation_err = 1;
#endif
if (NULL != cc) {
- if (cc->isSet(CC_MAX_AGE)) {
+ if (cc->haveMaxAge()) {
#if USE_HTTP_VIOLATIONS
if (R->flags.ignore_reload && cc->maxAge() == 0) {
debugs(22, 3, "refreshCheck: MAYBE: client-max-age = 0 and ignore-reload");
}
}
- if (cc->getMaxStale()>=0 && staleness > -1) {
- if (cc->getMaxStale()==HttpHdrCc::MAX_STALE_ALWAYS) {
+ if (cc->haveMaxStale() && staleness > -1) {
+ if (cc->maxStale()==HttpHdrCc::MAX_STALE_ALWAYS) {
/* max-stale directive without a value */
debugs(22, 3, "refreshCheck: NO: max-stale wildcard");
return FRESH_REQUEST_MAX_STALE_ALL;
- } else if (staleness < cc->getMaxStale()) {
+ } else if (staleness < cc->maxStale()) {
debugs(22, 3, "refreshCheck: NO: staleness < max-stale");
return FRESH_REQUEST_MAX_STALE_VALUE;
}