]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug #1057: New options to refresh-pattern configuration
authorhno <>
Sun, 7 Nov 2004 05:20:47 +0000 (05:20 +0000)
committerhno <>
Sun, 7 Nov 2004 05:20:47 +0000 (05:20 +0000)
By Przemek Czerkas and David S. Madole

This is based on patch by David S. Madole
http://www.omdev.com/squid/squid-2.2.STABLE4.ignore-no-cache.patch

I've added more options to refresh-pattern configuration:

- 'ignore-no-cache' ignores any "Pragma: no-cache" and "Cache-control:
   no-cache" headers received from a server,

- 'ignore-private' ignores any "Cache-control: private" headers
   received from a server,

- 'ignore-auth' caches responses to requests with authorization
   irrespective of "Cache-control: " headers received from a server.

Warning - these options VIOLATE the HTTP standard!

src/cache_cf.cc
src/cf.data.pre
src/http.cc
src/protos.h
src/refresh.cc
src/structs.h

index 50bcb536aacddcc80046eeb3617a51bc3e714d18..6bbdc1d1fdaa23c6e2dbad498816d7bde3401b6d 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: cache_cf.cc,v 1.455 2004/10/15 21:10:44 hno Exp $
+ * $Id: cache_cf.cc,v 1.456 2004/11/06 22:20:47 hno Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
@@ -525,6 +525,66 @@ configDoConfigure(void)
             break;
         }
 
+        for (R = Config.Refresh; R; R = R->next)
+        {
+            if (!R->flags.reload_into_ims)
+                continue;
+
+            debug(22, 1) ("WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP\n");
+
+            break;
+        }
+
+        for (R = Config.Refresh; R; R = R->next)
+        {
+            if (!R->flags.ignore_reload)
+                continue;
+
+            debug(22, 1) ("WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP\n");
+
+            break;
+        }
+
+        for (R = Config.Refresh; R; R = R->next)
+        {
+            if (!R->flags.ignore_no_cache)
+                continue;
+
+            debug(22, 1) ("WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP\n");
+
+            break;
+        }
+
+        for (R = Config.Refresh; R; R = R->next)
+        {
+            if (!R->flags.ignore_no_store)
+                continue;
+
+            debug(22, 1) ("WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP\n");
+
+            break;
+        }
+
+        for (R = Config.Refresh; R; R = R->next)
+        {
+            if (!R->flags.ignore_private)
+                continue;
+
+            debug(22, 1) ("WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP\n");
+
+            break;
+        }
+
+        for (R = Config.Refresh; R; R = R->next)
+        {
+            if (!R->flags.ignore_auth)
+                continue;
+
+            debug(22, 1) ("WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP\n");
+
+            break;
+        }
+
     }
 #endif
 #if !HTTP_VIOLATIONS
@@ -2019,6 +2079,18 @@ dump_refreshpattern(StoreEntry * entry, const char *name, refresh_t * head)
         if (head->flags.ignore_reload)
             storeAppendPrintf(entry, " ignore-reload");
 
+        if (head->flags.ignore_no_cache)
+            storeAppendPrintf(entry, " ignore-no-cache");
+
+        if (head->flags.ignore_no_store)
+            storeAppendPrintf(entry, " ignore-no-store");
+
+        if (head->flags.ignore_private)
+            storeAppendPrintf(entry, " ignore-private");
+
+        if (head->flags.ignore_auth)
+            storeAppendPrintf(entry, " ignore-auth");
+
 #endif
 
         storeAppendPrintf(entry, "\n");
@@ -2041,6 +2113,10 @@ parse_refreshpattern(refresh_t ** head)
     int override_lastmod = 0;
     int reload_into_ims = 0;
     int ignore_reload = 0;
+    int ignore_no_cache = 0;
+    int ignore_no_store = 0;
+    int ignore_private = 0;
+    int ignore_auth = 0;
 #endif
 
     int i;
@@ -2085,6 +2161,14 @@ parse_refreshpattern(refresh_t ** head)
             override_expire = 1;
         else if (!strcmp(token, "override-lastmod"))
             override_lastmod = 1;
+        else if (!strcmp(token, "ignore-no-cache"))
+            ignore_no_cache = 1;
+        else if (!strcmp(token, "ignore-no-store"))
+            ignore_no_store = 1;
+        else if (!strcmp(token, "ignore-private"))
+            ignore_private = 1;
+        else if (!strcmp(token, "ignore-auth"))
+            ignore_auth = 1;
         else if (!strcmp(token, "reload-into-ims")) {
             reload_into_ims = 1;
             refresh_nocache_hack = 1;
@@ -2136,6 +2220,18 @@ parse_refreshpattern(refresh_t ** head)
     if (ignore_reload)
         t->flags.ignore_reload = 1;
 
+    if (ignore_no_cache)
+        t->flags.ignore_no_cache = 1;
+
+    if (ignore_no_store)
+        t->flags.ignore_no_store = 1;
+
+    if (ignore_private)
+        t->flags.ignore_private = 1;
+
+    if (ignore_auth)
+        t->flags.ignore_auth = 1;
+
 #endif
 
     t->next = NULL;
index 84e592b97a3c35039b1f2c5837b72051eceee193..766811d516dedc7ffdda6c20f93a0eec372baa79 100644 (file)
@@ -1,6 +1,6 @@
 
 #
-# $Id: cf.data.pre,v 1.361 2004/10/20 22:41:04 hno Exp $
+# $Id: cf.data.pre,v 1.362 2004/11/06 22:20:47 hno Exp $
 #
 #
 # SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -2067,6 +2067,10 @@ DOC_START
                 override-lastmod
                 reload-into-ims
                 ignore-reload
+                ignore-no-cache
+                ignore-no-store
+                ignore-private
+                ignore-auth
 
                override-expire enforces min age even if the server
                sent a Expires: header. Doing this VIOLATES the HTTP
@@ -2086,6 +2090,28 @@ DOC_START
                this feature could make you liable for problems which
                it causes.
 
+                ignore-no-cache ignores any ``Pragma: no-cache'' and
+                ``Cache-control: no-cache'' headers received from a server.
+                The HTTP RFC never allows the use of this (Pragma) header
+                from a server, only a client, though plenty of servers
+                send it anyway.
+
+                ignore-no-store ignores any ``Cache-control: no-store''
+                headers received from a server. Doing this VIOLATES
+                the HTTP standard. Enabling this feature could make you
+                liable for problems which it causes.
+
+                ignore-private ignores any ``Cache-control: private''
+                headers received from a server. Doing this VIOLATES
+                the HTTP standard. Enabling this feature could make you
+                liable for problems which it causes.
+
+                ignore-auth caches responses to requests with authorization,
+                irrespective of ``Cache-control'' headers received from
+                a server. Doing this VIOLATES the HTTP standard. Enabling
+                this feature could make you liable for problems which
+                it causes.
+
        Basically a cached object is:
 
                FRESH if expires < now, else STALE
index 3d2c0dcaf09868a1ccdf22540668bd9b86122894..9bfbff7d7109cf0003600379741cbb7012e792aa 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: http.cc,v 1.433 2004/10/10 03:06:17 hno Exp $
+ * $Id: http.cc,v 1.434 2004/11/06 22:20:47 hno Exp $
  *
  * DEBUG: section 11    Hypertext Transfer Protocol (HTTP)
  * AUTHOR: Harvest Derived
@@ -329,25 +329,6 @@ HttpStateData::processSurrogateControl(HttpReply *reply)
 #endif
 }
 
-int
-cacheControlAllowsCaching(HttpHdrCc *cc)
-{
-    if (cc) {
-        const int cc_mask = cc->mask;
-
-        if (EBIT_TEST(cc_mask, CC_PRIVATE))
-            return 0;
-
-        if (EBIT_TEST(cc_mask, CC_NO_CACHE))
-            return 0;
-
-        if (EBIT_TEST(cc_mask, CC_NO_STORE))
-            return 0;
-    }
-
-    return 1;
-}
-
 int
 HttpStateData::cacheableReply()
 {
@@ -355,22 +336,50 @@ HttpStateData::cacheableReply()
     HttpHeader const *hdr = &rep->header;
     const int cc_mask = (rep->cache_control) ? rep->cache_control->mask : 0;
     const char *v;
+#if HTTP_VIOLATIONS
 
-    if (surrogateNoStore)
-        return 0;
+    const refresh_t *R = NULL;
+#endif
 
-    if (!cacheControlAllowsCaching(rep->cache_control))
+    if (surrogateNoStore)
         return 0;
 
     if (!ignoreCacheControl) {
-        if (EBIT_TEST(cc_mask, CC_PRIVATE))
-            return 0;
+        if (EBIT_TEST(cc_mask, CC_PRIVATE)) {
+#if HTTP_VIOLATIONS
 
-        if (EBIT_TEST(cc_mask, CC_NO_CACHE))
-            return 0;
+            if (!R)
+                R = refreshLimits(entry->mem_obj->url);
 
-        if (EBIT_TEST(cc_mask, CC_NO_STORE))
-            return 0;
+            if (R && !R->flags.ignore_private)
+#endif
+
+                return 0;
+        }
+
+        if (EBIT_TEST(cc_mask, CC_NO_CACHE)) {
+#if HTTP_VIOLATIONS
+
+            if (!R)
+                R = refreshLimits(entry->mem_obj->url);
+
+            if (R && !R->flags.ignore_no_cache)
+#endif
+
+                return 0;
+        }
+
+        if (EBIT_TEST(cc_mask, CC_NO_STORE)) {
+#if HTTP_VIOLATIONS
+
+            if (!R)
+                R = refreshLimits(entry->mem_obj->url);
+
+            if (R && !R->flags.ignore_no_store)
+#endif
+
+                return 0;
+        }
     }
 
     if (request->flags.auth) {
@@ -380,8 +389,17 @@ HttpStateData::cacheableReply()
          * RFC 2068, sec 14.9.4
          */
 
-        if (!EBIT_TEST(cc_mask, CC_PUBLIC))
-            return 0;
+        if (!EBIT_TEST(cc_mask, CC_PUBLIC)) {
+#if HTTP_VIOLATIONS
+
+            if (!R)
+                R = refreshLimits(entry->mem_obj->url);
+
+            if (R && !R->flags.ignore_auth)
+#endif
+
+                return 0;
+        }
     }
 
     /* Pragma: no-cache in _replies_ is not documented in HTTP,
@@ -391,8 +409,17 @@ HttpStateData::cacheableReply()
         const int no_cache = strListIsMember(&s, "no-cache", ',');
         s.clean();
 
-        if (no_cache)
-            return 0;
+        if (no_cache) {
+#if HTTP_VIOLATIONS
+
+            if (!R)
+                R = refreshLimits(entry->mem_obj->url);
+
+            if (R && !R->flags.ignore_no_cache)
+#endif
+
+                return 0;
+        }
     }
 
     /*
index c9da70aaade037641eb37fab5e61ec512a2ec68e..17c040cd7eaea25d3d96b06f9df15e4a41ee5fff 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: protos.h,v 1.496 2004/10/18 12:20:10 hno Exp $
+ * $Id: protos.h,v 1.497 2004/11/06 22:20:47 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -623,6 +623,7 @@ extern int refreshCheckHTCP(const StoreEntry *, HttpRequest *);
 extern int refreshCheckDigest(const StoreEntry *, time_t delta);
 extern time_t getMaxAge(const char *url);
 extern void refreshInit(void);
+extern const refresh_t *refreshLimits(const char *url);
 
 extern void serverConnectionsClose(void);
 extern void shut_down(int);
index 5f143eebd38bd035d1430f4170511807cf5440a9..46eef63f4ccb33ccfe321e993aa019f9b9e90adf 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: refresh.cc,v 1.63 2003/08/10 11:00:44 robertc Exp $
+ * $Id: refresh.cc,v 1.64 2004/11/06 22:20:47 hno Exp $
  *
  * DEBUG: section 22    Refresh Calculation
  * AUTHOR: Harvest Derived
@@ -115,14 +115,13 @@ refreshCounts[rcCount];
 #define REFRESH_DEFAULT_PCT    0.20
 #define REFRESH_DEFAULT_MAX    (time_t)259200
 
-static const refresh_t *refreshLimits(const char *);
 static const refresh_t *refreshUncompiledPattern(const char *);
 static OBJH refreshStats;
 static int refreshStaleness(const StoreEntry *, time_t, time_t, const refresh_t *, stale_flags *);
 
 static refresh_t DefaultRefresh;
 
-static const refresh_t *
+const refresh_t *
 refreshLimits(const char *url)
 {
     const refresh_t *R;
index 2ac1adf719710d52c608d32923b3f1c74db724b0..ecf496397c1067217b79ee7527c993b42dc760b3 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: structs.h,v 1.493 2004/10/18 12:20:10 hno Exp $
+ * $Id: structs.h,v 1.494 2004/11/06 22:20:48 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -1516,6 +1516,18 @@ unsigned int reload_into_ims:
 
 unsigned int ignore_reload:
         1;
+
+unsigned int ignore_no_cache:
+        1;
+
+unsigned int ignore_no_store:
+        1;
+
+unsigned int ignore_private:
+        1;
+
+unsigned int ignore_auth:
+        1;
 #endif
 
     }