]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
mod_cache: Teach CacheEnable and CacheDisable to work from within a
authorGraham Leggett <minfrin@apache.org>
Mon, 5 Oct 2009 20:27:19 +0000 (20:27 +0000)
committerGraham Leggett <minfrin@apache.org>
Mon, 5 Oct 2009 20:27:19 +0000 (20:27 +0000)
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

CHANGES
docs/manual/mod/mod_cache.xml
modules/cache/mod_cache.c

diff --git a/CHANGES b/CHANGES
index b4b649cc7e1dbef6255348c3b35081ab791adac9..a3e1ec325d61bb353001a02fc0fd778e33ae838d 100644 (file)
--- 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 <sf fritsch.de>, 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]
 
index 556de0dfd95c6ec20ba7cf37373f15d69d491aa3..e1c958cb82c1f9e8500e80e3b01c960b28d9075d 100644 (file)
@@ -238,7 +238,9 @@ manager</description>
     <p>The <directive>CacheEnable</directive> directive instructs
     <module>mod_cache</module> to cache urls at or below
     <var>url-string</var>. The cache storage manager is specified with the
-    <var>cache_type</var> argument. 
+    <var>cache_type</var> argument. If the <directive>CacheEnable</directive>
+    directive is placed inside a <directive type="section">Location</directive>
+    directive, the <var>url-string</var> becomes optional.
     <var>cache_type</var> <code>disk</code> instructs
     <module>mod_cache</module> to use the disk based storage manager
     implemented by <module>mod_disk_cache</module>.</p>
@@ -284,7 +286,7 @@ manager</description>
 <directivesynopsis>
 <name>CacheDisable</name>
 <description>Disable caching of specified URLs</description>
-<syntax>CacheDisable <var> url-string</var></syntax>
+<syntax>CacheDisable <var>url-string</var> | <var>on</var></syntax>
 <contextlist><context>server config</context><context>virtual host</context>
 </contextlist>
 
@@ -297,6 +299,16 @@ manager</description>
       CacheDisable /local_files
     </example>
 
+    <p>If used in a <directive type="section">Location</directive> 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.</p>
+
+    <example><title>Example</title>
+      &lt;Location /foo&gt;<br />
+        CacheDisable on<br />
+      &lt;/Location&gt;<br />
+    </example>
+
     <p> The <code>no-cache</code> environment variable can be set to 
     disable caching on a finer grained set of resources in versions
     2.2.12 and later.</p>
index c97b39217e7babc6e2a9dbec429cf75bcb312ad1..78472c33585f6396b0ea2da1ebb44bbaa5c199bc 100644 (file)
@@ -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"),