From: Graham Leggett Date: Mon, 5 Oct 2009 20:27:19 +0000 (+0000) Subject: mod_cache: Teach CacheEnable and CacheDisable to work from within a X-Git-Tag: 2.3.3~195 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ae50b75b92871cd6abfc8b2d4b2089a05ade3077;p=thirdparty%2Fapache%2Fhttpd.git mod_cache: Teach CacheEnable and CacheDisable to work from within a Location section, in line with how ProxyPass works. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@821993 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index b4b649cc7e1..a3e1ec325d6 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,9 @@ Changes with Apache 2.3.3 mod_proxy_ftp: NULL pointer dereference on error paths. [Stefan Fritsch , Joe Orton] + *) mod_cache: Teach CacheEnable and CacheDisable to work from within a + Location section, in line with how ProxyPass works. [Graham Leggett] + *) mod_reqtimeout: New module to set timeouts and minimum data rates for receiving requests from the client. [Stefan Fritsch] diff --git a/docs/manual/mod/mod_cache.xml b/docs/manual/mod/mod_cache.xml index 556de0dfd95..e1c958cb82c 100644 --- a/docs/manual/mod/mod_cache.xml +++ b/docs/manual/mod/mod_cache.xml @@ -238,7 +238,9 @@ manager

The CacheEnable directive instructs mod_cache to cache urls at or below url-string. The cache storage manager is specified with the - cache_type argument. + cache_type argument. If the CacheEnable + directive is placed inside a Location + directive, the url-string becomes optional. cache_type disk instructs mod_cache to use the disk based storage manager implemented by mod_disk_cache.

@@ -284,7 +286,7 @@ manager CacheDisable Disable caching of specified URLs -CacheDisable url-string +CacheDisable url-string | on server configvirtual host @@ -297,6 +299,16 @@ manager CacheDisable /local_files +

If used in a Location directive, + the path needs to be specified below the Location, or if the word "on" + is used, caching for the whole location will be disabled.

+ + Example + <Location /foo>
+ CacheDisable on
+ </Location>
+
+

The no-cache environment variable can be set to disable caching on a finer grained set of resources in versions 2.2.12 and later.

diff --git a/modules/cache/mod_cache.c b/modules/cache/mod_cache.c index c97b39217e7..78472c33585 100644 --- a/modules/cache/mod_cache.c +++ b/modules/cache/mod_cache.c @@ -1516,12 +1516,30 @@ static const char *add_cache_enable(cmd_parms *parms, void *dummy, cache_server_conf *conf; struct cache_enable *new; + const char *err = ap_check_cmd_context(parms, + NOT_IN_DIRECTORY|NOT_IN_LIMIT|NOT_IN_FILES); + if (err != NULL) { + return err; + } + if (*type == '/') { return apr_psprintf(parms->pool, "provider (%s) starts with a '/'. Are url and provider switched?", type); } + if (!url) { + url = parms->path; + } + if (!url) { + return apr_psprintf(parms->pool, + "CacheEnable provider (%s) is missing an URL.", type); + } + if (parms->path && strncmp(parms->path, url, strlen(parms->path))) { + return "When in a Location, CacheEnable must specify a path or an URL below " + "that location."; + } + conf = (cache_server_conf *)ap_get_module_config(parms->server->module_config, &cache_module); @@ -1545,6 +1563,25 @@ static const char *add_cache_disable(cmd_parms *parms, void *dummy, cache_server_conf *conf; struct cache_disable *new; + const char *err = ap_check_cmd_context(parms, + NOT_IN_DIRECTORY|NOT_IN_LIMIT|NOT_IN_FILES); + if (err != NULL) { + return err; + } + + if (parms->path && !strcmp(url, "on")) { + url = parms->path; + } + if (url[0] != '/' && !strchr(url, ':')) { + return "CacheDisable must specify a path or an URL, or when in a Location, " + "the word 'on'."; + } + + if (parms->path && strncmp(parms->path, url, strlen(parms->path))) { + return "When in a Location, CacheDisable must specify a path or an URL below " + "that location."; + } + conf = (cache_server_conf *)ap_get_module_config(parms->server->module_config, &cache_module); @@ -1704,10 +1741,10 @@ static const command_rec cache_cmds[] = * This is more intuitive that requiring a LoadModule directive. */ - AP_INIT_TAKE2("CacheEnable", add_cache_enable, NULL, RSRC_CONF, - "A cache type and partial URL prefix below which " - "caching is enabled"), - AP_INIT_TAKE1("CacheDisable", add_cache_disable, NULL, RSRC_CONF, + AP_INIT_TAKE12("CacheEnable", add_cache_enable, NULL, RSRC_CONF|ACCESS_CONF, + "A cache type and partial URL prefix below which " + "caching is enabled"), + AP_INIT_TAKE1("CacheDisable", add_cache_disable, NULL, RSRC_CONF|ACCESS_CONF, "A partial URL prefix below which caching is disabled"), AP_INIT_TAKE1("CacheMaxExpire", set_cache_maxex, NULL, RSRC_CONF, "The maximum time in seconds to cache a document"),