File 12491.patch of Package squid

---------------------
PatchSet 12491 
Date: 2009/06/25 22:55:50
Author: hno
Branch: SQUID_2_7
Tag: (none) 
Log:
Author: Mark Nottingham <mnot@pobox.com>
MFC: Bug #2647: Reprioritise override-* and stale-while-revalidate

In the "At this point the response is stale" section of refreshCheck(), Squid
does the stale-while-revalidate and stale-if-error checks before the checks for
override-expire and override-lastmod.

In some circumstances, this can cause undesireable side effects. For example, a
response with an invalid Expires header, an Expires header in the past, or
Cache-Control: max-age=0, in combination with

refresh_pattern . 1 100% 1 override-expire stale-while-revalidate=15

will, once the one minute window passes, go into a state where requests are
always served as TCP_STALE_HIT (with a corresponding TCP_ASYNC_MISS), as long
as a request comes in the 15 second stale-while-revalidate window and at least
once every 15 seconds thereafter.

The fix is to place the override-* checks before the stale-while-revalidate
logic, so that an already-stale response has the overridden freshness applied
before the stale checks happen.

Members: 
	src/refresh.c:1.67->1.67.2.1 

Index: squid/src/refresh.c
===================================================================
RCS file: /cvsroot/squid/squid/src/refresh.c,v
retrieving revision 1.67
retrieving revision 1.67.2.1
diff -u -r1.67 -r1.67.2.1
--- squid/src/refresh.c	13 Dec 2007 01:25:34 -0000	1.67
+++ squid/src/refresh.c	25 Jun 2009 22:55:50 -0000	1.67.2.1
@@ -1,6 +1,6 @@
 
 /*
- * $Id: refresh.c,v 1.67 2007/12/13 01:25:34 hno Exp $
+ * $Id: refresh.c,v 1.67.2.1 2009/06/25 22:55:50 hno Exp $
  *
  * DEBUG: section 22    Refresh Calculation
  * AUTHOR: Harvest Derived
@@ -334,6 +334,16 @@
      * At this point the response is stale, unless one of
      * the override options kicks in.
      */
+#if HTTP_VIOLATIONS
+    if (sf.expires && R->flags.override_expire && age < R->min) {
+	debug(22, 3) ("refreshCheck: NO: age < min && override-expire\n");
+	return FRESH_OVERRIDE_EXPIRES;
+    }
+    if (sf.lmfactor && R->flags.override_lastmod && age < R->min) {
+	debug(22, 3) ("refreshCheck: NO: age < min && override-lastmod\n");
+	return FRESH_OVERRIDE_LASTMOD;
+    }
+#endif
     if (entry->mem_obj) {
 	int stale_while_revalidate = -1;
 	if (entry->mem_obj->reply && entry->mem_obj->reply->cache_control && EBIT_TEST(entry->mem_obj->reply->cache_control->mask, CC_STALE_WHILE_REVALIDATE))
@@ -357,26 +367,12 @@
     if (delta < 0 && staleness + delta < 0) {
 	return STALE_WITHIN_DELTA;
     }
-    if (sf.expires) {
-#if HTTP_VIOLATIONS
-	if (R->flags.override_expire && age < R->min) {
-	    debug(22, 3) ("refreshCheck: NO: age < min && override-expire\n");
-	    return FRESH_OVERRIDE_EXPIRES;
-	}
-#endif
+    if (sf.expires)
 	return STALE_EXPIRES;
-    }
     if (sf.max)
 	return STALE_MAX_RULE;
-    if (sf.lmfactor) {
-#if HTTP_VIOLATIONS
-	if (R->flags.override_lastmod && age < R->min) {
-	    debug(22, 3) ("refreshCheck: NO: age < min && override-lastmod\n");
-	    return FRESH_OVERRIDE_LASTMOD;
-	}
-#endif
+    if (sf.lmfactor)
 	return STALE_LMFACTOR_RULE;
-    }
     return STALE_DEFAULT;
 }
 
openSUSE Build Service is sponsored by