From: hno <> Date: Sun, 7 Nov 2004 05:20:47 +0000 (+0000) Subject: Bug #1057: New options to refresh-pattern configuration X-Git-Tag: SQUID_3_0_PRE4~1000 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=38f9c54773513ecc64a18c3b35c0b0fa091fbc9a;p=thirdparty%2Fsquid.git Bug #1057: New options to refresh-pattern configuration 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! --- diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 50bcb536aa..6bbdc1d1fd 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -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; diff --git a/src/cf.data.pre b/src/cf.data.pre index 84e592b97a..766811d516 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -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 diff --git a/src/http.cc b/src/http.cc index 3d2c0dcaf0..9bfbff7d71 100644 --- a/src/http.cc +++ b/src/http.cc @@ -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; + } } /* diff --git a/src/protos.h b/src/protos.h index c9da70aaad..17c040cd7e 100644 --- a/src/protos.h +++ b/src/protos.h @@ -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); diff --git a/src/refresh.cc b/src/refresh.cc index 5f143eebd3..46eef63f4c 100644 --- a/src/refresh.cc +++ b/src/refresh.cc @@ -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; diff --git a/src/structs.h b/src/structs.h index 2ac1adf719..ecf496397c 100644 --- a/src/structs.h +++ b/src/structs.h @@ -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 }