From: Amos Jeffries Date: Mon, 27 Dec 2010 20:25:30 +0000 (-0700) Subject: Author: Henrik Nordstrom X-Git-Tag: take00~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=65fd3895b2054d8da3617e3d6ef5ad3277b1f5d8;p=thirdparty%2Fsquid.git Author: Henrik Nordstrom Support RFC 5861 Cache-Control: stale-if-error option The default behaviour for Squid is to present the stale object when revalidation fails with a 5xx error. stale-if-error places a maximum limit on how long this stale object may be sent. After the limit has passed Squid is required to present the 5xx message to the client. Original code for Squid-2 was sponsored by Yahoo!. Portage done by Alex Rousskov and Amos Jeffries. --- diff --git a/SPONSORS b/SPONSORS index 02855238f1..1c570e925f 100644 --- a/SPONSORS +++ b/SPONSORS @@ -82,3 +82,9 @@ BBC (UK) and Siemens IT Solutions and Services (UK) Provided developement and testing resources for Solaris /dev/poll support. + +Yahoo! Inc. - http://www.yahoo.com/ + + Yahoo! Inc. supported the development of improved refresh + logics. Many thanks to Yahoo! Inc. for supporting the development + of these features. diff --git a/src/HttpHdrCc.cc b/src/HttpHdrCc.cc index 502ba8e864..3214313148 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}, + {"stale-if-error", (http_hdr_type)CC_STALE_IF_ERROR}, {"min-fresh", (http_hdr_type)CC_MIN_FRESH}, {"Other,", (http_hdr_type)CC_OTHER} /* ',' will protect from matches */ }; @@ -192,6 +193,14 @@ httpHdrCcParseInit(HttpHdrCc * cc, const String * str) break; + case CC_STALE_IF_ERROR: + if (!p || !httpHeaderParseInt(p, &cc->stale_if_error)) { + debugs(65, 2, "cc: invalid stale-if-error specs near '" << item << "'"); + cc->stale_if_error = -1; + EBIT_CLR(cc->mask, type); + } + break; + case CC_OTHER: if (cc->other.size()) diff --git a/src/enums.h b/src/enums.h index da1e39f68a..e5ddbfb2a3 100644 --- a/src/enums.h +++ b/src/enums.h @@ -100,6 +100,7 @@ typedef enum { CC_MAX_STALE, CC_MIN_FRESH, CC_ONLY_IF_CACHED, + CC_STALE_IF_ERROR, CC_OTHER, CC_ENUM_END } http_hdr_cc_type; diff --git a/src/refresh.cc b/src/refresh.cc index 17b97ef1c0..6d8c160d27 100644 --- a/src/refresh.cc +++ b/src/refresh.cc @@ -283,6 +283,15 @@ refreshCheck(const StoreEntry * entry, HttpRequest * request, time_t delta) debugs(22, 3, "Staleness = " << staleness); + // 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 && + EBIT_TEST(entry->mem_obj->getReply()->cache_control->mask, CC_STALE_IF_ERROR) && + entry->mem_obj->getReply()->cache_control->stale_if_error < staleness) { + + debugs(22, 3, "refreshCheck: stale-if-error period expired."); + request->flags.fail_on_validation_err = 1; + } + if (EBIT_TEST(entry->flags, ENTRY_REVALIDATE) && staleness > -1 #if USE_HTTP_VIOLATIONS && !R->flags.ignore_must_revalidate diff --git a/src/structs.h b/src/structs.h index e898fe5d81..badbc3ad84 100644 --- a/src/structs.h +++ b/src/structs.h @@ -714,6 +714,7 @@ public: int max_age; int s_maxage; int max_stale; + int stale_if_error; int min_fresh; String other; };