]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Henrik Nordstrom <hno@squid-cache.org>
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 14 Jan 2011 05:02:13 +0000 (22:02 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 14 Jan 2011 05:02:13 +0000 (22:02 -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 efee9c1bc65cd73318bab51a2c6bdfe4ab2da463..5b089106baaf481e67642f0e93d974ca0b9f7683 100644 (file)
@@ -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;
index 4086fe5e88a1bf787d044f5d0b7d8f7b7415065f..6f8e0d8d32f106c5d4eafe206ea4eb823d24c14e 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 HTTP_VIOLATIONS
             && !R->flags.ignore_must_revalidate
index 42d2e82e2c8d1c3eef3d72bb55fb70dcd58a0674..593c753782964dcf15d8b729dbda4adc768831b7 100644 (file)
@@ -724,6 +724,7 @@ public:
     int max_age;
     int s_maxage;
     int max_stale;
+    int stale_if_error;
     int min_fresh;
     String other;
 };