]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Henrik Nordstrom <hno@squid-cache.org>
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 27 Dec 2010 20:25:30 +0000 (13:25 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 27 Dec 2010 20:25:30 +0000 (13:25 -0700)
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.

SPONSORS
src/HttpHdrCc.cc
src/enums.h
src/refresh.cc
src/structs.h

index 02855238f13128718da5dc2f9f211651e147634e..1c570e925fa3e28b322ab32d57b07aebbebe5be3 100644 (file)
--- 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.
index 502ba8e864320ef7341fa36cfa0e1e5f5a521725..3214313148a90bd0ae97f73266451c161cb178af 100644 (file)
@@ -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())
index da1e39f68a176321d8303d976bb4994da96cadc2..e5ddbfb2a34ec58dcb887c21f2faeab2b06f72dd 100644 (file)
@@ -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;
index 17b97ef1c0f45d72ac26fe295744480240cc1a4a..6d8c160d2774abb0851ce863683bae3733788265 100644 (file)
@@ -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
index e898fe5d814e5ff223c8b9ddf3f442b26f509c33..badbc3ad84543ca5a0cee3c51ace626ecbf134dd 100644 (file)
@@ -714,6 +714,7 @@ public:
     int max_age;
     int s_maxage;
     int max_stale;
+    int stale_if_error;
     int min_fresh;
     String other;
 };