From: Amos Jeffries Date: Fri, 14 Jan 2011 05:02:13 +0000 (-0700) Subject: Author: Henrik Nordstrom X-Git-Tag: SQUID_3_1_11~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa5f2a8c0ae80f8b208be35559dcf73b3a094454;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 efee9c1bc6..5b089106ba 100644 --- a/src/enums.h +++ b/src/enums.h @@ -147,6 +147,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 4086fe5e88..6f8e0d8d32 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 HTTP_VIOLATIONS && !R->flags.ignore_must_revalidate diff --git a/src/structs.h b/src/structs.h index 42d2e82e2c..593c753782 100644 --- a/src/structs.h +++ b/src/structs.h @@ -724,6 +724,7 @@ public: int max_age; int s_maxage; int max_stale; + int stale_if_error; int min_fresh; String other; };