From 79c3514f37e64d700100ed289064c477671ac14a Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Sat, 23 Oct 2010 07:41:01 -0600 Subject: [PATCH] Author: Alex Rousskov HTTP Compliance: support requests with Cache-Control: min-fresh. Added min-fresh directive support for Cache-Control header. The directive is handled in refreshCheck() by incrementing age and check_time by min-fresh value. Co-Advisor test case: test_case/rfc2616/ccReqDirMsg-min-fresh-obey --- src/HttpHdrCc.cc | 17 ++++++++++++++++- src/enums.h | 1 + src/refresh.cc | 28 ++++++++++++++++++++-------- src/structs.h | 1 + 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/HttpHdrCc.cc b/src/HttpHdrCc.cc index cc9356bad0..502ba8e864 100644 --- a/src/HttpHdrCc.cc +++ b/src/HttpHdrCc.cc @@ -51,6 +51,7 @@ static const HttpHeaderFieldAttrs CcAttrs[CC_ENUM_END] = { {"max-age", (http_hdr_type)CC_MAX_AGE}, {"s-maxage", (http_hdr_type)CC_S_MAXAGE}, {"max-stale", (http_hdr_type)CC_MAX_STALE}, + {"min-fresh", (http_hdr_type)CC_MIN_FRESH}, {"Other,", (http_hdr_type)CC_OTHER} /* ',' will protect from matches */ }; @@ -89,7 +90,7 @@ HttpHdrCc * httpHdrCcCreate(void) { HttpHdrCc *cc = (HttpHdrCc *)memAllocate(MEM_HTTP_HDR_CC); - cc->max_age = cc->s_maxage = cc->max_stale = -1; + cc->max_age = cc->s_maxage = cc->max_stale = cc->min_fresh = -1; return cc; } @@ -181,6 +182,16 @@ httpHdrCcParseInit(HttpHdrCc * cc, const String * str) break; + case CC_MIN_FRESH: + + if (!p || !httpHeaderParseInt(p, &cc->min_fresh)) { + debugs(65, 2, "cc: invalid min-fresh specs near '" << item << "'"); + cc->min_fresh = -1; + EBIT_CLR(cc->mask, type); + } + + break; + case CC_OTHER: if (cc->other.size()) @@ -220,6 +231,7 @@ httpHdrCcDup(const HttpHdrCc * cc) dup->max_age = cc->max_age; dup->s_maxage = cc->s_maxage; dup->max_stale = cc->max_stale; + dup->min_fresh = cc->min_fresh; return dup; } @@ -248,6 +260,9 @@ httpHdrCcPackInto(const HttpHdrCc * cc, Packer * p) if (flag == CC_MAX_STALE && cc->max_stale >= 0) packerPrintf(p, "=%d", (int) cc->max_stale); + if (flag == CC_MIN_FRESH) + packerPrintf(p, "=%d", (int) cc->min_fresh); + pcount++; } } diff --git a/src/enums.h b/src/enums.h index cb1f5f0b39..f3b4bfde33 100644 --- a/src/enums.h +++ b/src/enums.h @@ -144,6 +144,7 @@ typedef enum { CC_MAX_AGE, CC_S_MAXAGE, CC_MAX_STALE, + CC_MIN_FRESH, CC_ONLY_IF_CACHED, CC_OTHER, CC_ENUM_END diff --git a/src/refresh.cc b/src/refresh.cc index dc39714f72..a61e5d820d 100644 --- a/src/refresh.cc +++ b/src/refresh.cc @@ -254,23 +254,35 @@ refreshCheck(const StoreEntry * entry, HttpRequest * request, time_t delta) if (NULL == R) R = &DefaultRefresh; - memset(&sf, '\0', sizeof(sf)); - - staleness = refreshStaleness(entry, check_time, age, R, &sf); - - debugs(22, 3, "Staleness = " << staleness); - debugs(22, 3, "refreshCheck: Matched '" << R->pattern << " " << (int) R->min << " " << (int) (100.0 * R->pct) << "%% " << (int) R->max << "'"); - - debugs(22, 3, "refreshCheck: age = " << age); + debugs(22, 3, "\tage:\t" << age); debugs(22, 3, "\tcheck_time:\t" << mkrfc1123(check_time)); debugs(22, 3, "\tentry->timestamp:\t" << mkrfc1123(entry->timestamp)); + if (request && !request->flags.ignore_cc) { + const HttpHdrCc *const cc = request->cache_control; + if (cc && cc->min_fresh > 0) { + debugs(22, 3, "\tage + min-fresh:\t" << age << " + " << + cc->min_fresh << " = " << age + cc->min_fresh); + debugs(22, 3, "\tcheck_time + min-fresh:\t" << check_time << " + " + << cc->min_fresh << " = " << + mkrfc1123(check_time + cc->min_fresh)); + age += cc->min_fresh; + check_time += cc->min_fresh; + } + } + + memset(&sf, '\0', sizeof(sf)); + + staleness = refreshStaleness(entry, check_time, age, R, &sf); + + debugs(22, 3, "Staleness = " << staleness); + if (EBIT_TEST(entry->flags, ENTRY_REVALIDATE) && staleness > -1 #if HTTP_VIOLATIONS && !R->flags.ignore_must_revalidate diff --git a/src/structs.h b/src/structs.h index 6e8bbc24e3..05e61a2b5e 100644 --- a/src/structs.h +++ b/src/structs.h @@ -723,6 +723,7 @@ public: int max_age; int s_maxage; int max_stale; + int min_fresh; String other; }; -- 2.47.2