httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r239421 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mod_cache.html.en docs/manual/mod/mod_cache.xml modules/cache/cache_util.c modules/cache/mod_cache.c modules/cache/mod_cache.h
Date Tue, 23 Aug 2005 15:43:28 GMT
Author: colm
Date: Tue Aug 23 08:43:23 2005
New Revision: 239421

URL: http://svn.apache.org/viewcvs?rev=239421&view=rev
Log:

Enhance CacheEnable/CacheDisable to control caching on a per-protocol, per-host
and per-path basis. Makes Cache(En|Dis)able useful for forward proxy servers.


Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/docs/manual/mod/mod_cache.html.en
    httpd/httpd/trunk/docs/manual/mod/mod_cache.xml
    httpd/httpd/trunk/modules/cache/cache_util.c
    httpd/httpd/trunk/modules/cache/mod_cache.c
    httpd/httpd/trunk/modules/cache/mod_cache.h

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/CHANGES?rev=239421&r1=239420&r2=239421&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Tue Aug 23 08:43:23 2005
@@ -2,6 +2,10 @@
 Changes with Apache 2.3.0
   [Remove entries to the current 2.0 and 2.2 section below, when backported]
 
+  *) mod_cache: Enhance CacheEnable/CacheDisable to control caching on a
+     per-protocol, per-host and per-path basis. Intended for proxy
+     configurations. [Colm MacCarthaigh]
+
   *) Teach mod_ssl to use arbitraty OIDs in an SSLRequire directive,
      allowing string-valued client certificate attributes to be used for
      access control, as in: SSLRequire "value" in OID("1.3.6.1.4.1.18060.1")

Modified: httpd/httpd/trunk/docs/manual/mod/mod_cache.html.en
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/docs/manual/mod/mod_cache.html.en?rev=239421&r1=239420&r2=239421&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mod_cache.html.en (original)
+++ httpd/httpd/trunk/docs/manual/mod/mod_cache.html.en Tue Aug 23 08:43:23 2005
@@ -87,8 +87,8 @@
       &lt;IfModule mod_cache.c&gt;<br />
       <span class="indent">
         #LoadModule disk_cache_module modules/mod_disk_cache.so<br />
-        # If you want to use mod_disk_cache instead of mod_mem_cache,
-        # uncomment the line above and comment out the LoadModule line below.
+        # If you want to use mod_disk_cache instead of mod_mem_cache,<br />
+        # uncomment the line above and comment out the LoadModule line below.<br />
         &lt;IfModule mod_disk_cache.c&gt;<br />
         <span class="indent">
           CacheRoot c:/cacheroot<br />
@@ -108,6 +108,9 @@
           MCacheMaxObjectSize 2048<br />
         </span>
         &lt;/IfModule&gt;<br />
+        <br />
+        # When acting as a proxy, don't cache the list of security updates<br />
+        CacheDisable http://security.update.server/update-list/<br />
       </span>
       &lt;/IfModule&gt;
     </code></p></div>
@@ -184,6 +187,20 @@
       CacheEnable  fd    /images<br />
       CacheEnable  disk  /<br />
     </code></p></div>
+
+    <p>When acting as a forward proxy server, <var>url-string</var> can
+    also be used to specify remote sites and proxy protocols which 
+    caching should be enabled for.</p>
+ 
+    <div class="example"><p><code>
+      # Cache proxied url's<br />
+      CacheEnable  disk  /<br /><br />
+      # Cache FTP-proxied url's<br />
+      CacheEnable  disk  ftp://<br /><br />
+      # Cache content from www.apache.org<br />
+      CacheEnable  disk  http://www.apache.org/<br />
+    </code></p></div>
+
 
 </div>
 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif"
/></a></div>

Modified: httpd/httpd/trunk/docs/manual/mod/mod_cache.xml
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/docs/manual/mod/mod_cache.xml?rev=239421&r1=239420&r2=239421&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mod_cache.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/mod_cache.xml Tue Aug 23 08:43:23 2005
@@ -86,8 +86,8 @@
       &lt;IfModule mod_cache.c&gt;<br />
       <indent>
         #LoadModule disk_cache_module modules/mod_disk_cache.so<br />
-        # If you want to use mod_disk_cache instead of mod_mem_cache,
-        # uncomment the line above and comment out the LoadModule line below.
+        # If you want to use mod_disk_cache instead of mod_mem_cache,<br />
+        # uncomment the line above and comment out the LoadModule line below.<br />
         &lt;IfModule mod_disk_cache.c&gt;<br />
         <indent>
           CacheRoot c:/cacheroot<br />
@@ -107,6 +107,9 @@
           MCacheMaxObjectSize 2048<br />
         </indent>
         &lt;/IfModule&gt;<br />
+        <br />
+        # When acting as a proxy, don't cache the list of security updates<br />
+        CacheDisable http://security.update.server/update-list/<br />
       </indent>
       &lt;/IfModule&gt;
     </example>
@@ -145,6 +148,20 @@
       CacheEnable  fd    /images<br />
       CacheEnable  disk  /<br />
     </example>
+
+    <p>When acting as a forward proxy server, <var>url-string</var> can
+    also be used to specify remote sites and proxy protocols which 
+    caching should be enabled for.</p>
+ 
+    <example>
+      # Cache proxied url's<br />
+      CacheEnable  disk  /<br /><br />
+      # Cache FTP-proxied url's<br />
+      CacheEnable  disk  ftp://<br /><br />
+      # Cache content from www.apache.org<br />
+      CacheEnable  disk  http://www.apache.org/<br />
+    </example>
+
 </usage>
 </directivesynopsis>
 

Modified: httpd/httpd/trunk/modules/cache/cache_util.c
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/modules/cache/cache_util.c?rev=239421&r1=239420&r2=239421&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/cache/cache_util.c (original)
+++ httpd/httpd/trunk/modules/cache/cache_util.c Tue Aug 23 08:43:23 2005
@@ -24,23 +24,65 @@
 
 extern module AP_MODULE_DECLARE_DATA cache_module;
 
+/* Determine if "url" matches the hostname, scheme and port and path
+ * in "filter". All but the path comparisons are case-insensitive.
+ */
+static int uri_meets_conditions(apr_uri_t filter, int pathlen, apr_uri_t url)
+{
+    /* Compare the hostnames */
+    if(filter.hostname) {
+        if (!url.hostname) {
+            return 0;
+        }
+        else if (strcasecmp(filter.hostname, url.hostname)) {
+            return 0;
+        }
+    }
+
+    /* Compare the schemes */
+    if(filter.scheme) {
+        if (!url.scheme) {
+            return 0;
+        }
+        else if (strcasecmp(filter.scheme, url.scheme)) {
+            return 0;
+        }
+    }
+    
+    /* Compare the ports */
+    if(filter.port_str) {
+        if (url.port_str && filter.port != url.port) {
+            return 0;
+        }
+        /* NOTE:  ap_port_of_scheme will return 0 if given NULL input */
+        else if (filter.port != apr_uri_port_of_scheme(url.scheme)) {
+            return 0;
+        }
+    }
+    else if(url.port_str && filter.scheme) {
+        if (apr_uri_port_of_scheme(filter.scheme) == url.port) {
+            return 0;
+        }
+    }
+    
+    /* Url has met all of the filter conditions so far, determine
+     * if the paths match.
+     */
+    return !strncmp(filter.path, url.path, pathlen);
+}
 
 CACHE_DECLARE(cache_provider_list *)ap_cache_get_providers(request_rec *r,
                                                   cache_server_conf *conf, 
-                                                  const char *url)
+                                                  apr_uri_t uri)
 {
     cache_provider_list *providers = NULL;
     int i;
 
-    /* we can't cache if there's no URL */
-    /* Is this case even possible?? */
-    if (!url) return NULL;
-
     /* loop through all the cacheenable entries */
     for (i = 0; i < conf->cacheenable->nelts; i++) {
         struct cache_enable *ent = 
                                 (struct cache_enable *)conf->cacheenable->elts;
-        if ((ent[i].url) && !strncasecmp(url, ent[i].url, ent[i].urllen)) {
+        if (uri_meets_conditions(ent[i].url, ent[i].pathlen, uri)) {
             /* Fetch from global config and add to the list. */
             cache_provider *provider;
             provider = ap_lookup_provider(CACHE_PROVIDER_GROUP, ent[i].type,
@@ -77,7 +119,7 @@
     for (i = 0; i < conf->cachedisable->nelts; i++) {
         struct cache_disable *ent = 
                                (struct cache_disable *)conf->cachedisable->elts;
-        if ((ent[i].url) && !strncasecmp(url, ent[i].url, ent[i].urllen)) {
+        if (uri_meets_conditions(ent[i].url, ent[i].pathlen, uri)) {
             /* Stop searching now. */
             return NULL;
         }

Modified: httpd/httpd/trunk/modules/cache/mod_cache.c
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/modules/cache/mod_cache.c?rev=239421&r1=239420&r2=239421&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/cache/mod_cache.c (original)
+++ httpd/httpd/trunk/modules/cache/mod_cache.c Tue Aug 23 08:43:23 2005
@@ -50,8 +50,6 @@
 {
     apr_status_t rv;
     const char *auth;
-    apr_uri_t uri;
-    char *path;
     cache_provider_list *providers;
     cache_request_rec *cache;
     cache_server_conf *conf;
@@ -62,16 +60,13 @@
         return DECLINED;
     }
 
-    uri = r->parsed_uri;
-    path = uri.path;
-
     conf = (cache_server_conf *) ap_get_module_config(r->server->module_config,
                                                       &cache_module);
 
     /*
      * Which cache module (if any) should handle this request?
      */
-    if (!(providers = ap_cache_get_providers(r, conf, path))) {
+    if (!(providers = ap_cache_get_providers(r, conf, r->parsed_uri))) {
         return DECLINED;
     }
 
@@ -984,8 +979,15 @@
                                                   &cache_module);
     new = apr_array_push(conf->cacheenable);
     new->type = type;
-    new->url = url;
-    new->urllen = strlen(url);
+    if (apr_uri_parse(parms->pool, url, &(new->url))) {
+        return NULL;
+    }
+    if (new->url.path) {
+        new->pathlen = strlen(new->url.path);
+    } else {
+        new->pathlen = 1;
+        new->url.path = "/";
+    }
     return NULL;
 }
 
@@ -999,8 +1001,15 @@
         (cache_server_conf *)ap_get_module_config(parms->server->module_config,
                                                   &cache_module);
     new = apr_array_push(conf->cachedisable);
-    new->url = url;
-    new->urllen = strlen(url);
+    if (apr_uri_parse(parms->pool, url, &(new->url))) {
+        return NULL;
+    }
+    if (new->url.path) {
+        new->pathlen = strlen(new->url.path);
+    } else {
+        new->pathlen = 1;
+        new->url.path = "/";
+    }
     return NULL;
 }
 

Modified: httpd/httpd/trunk/modules/cache/mod_cache.h
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/modules/cache/mod_cache.h?rev=239421&r1=239420&r2=239421&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/cache/mod_cache.h (original)
+++ httpd/httpd/trunk/modules/cache/mod_cache.h Tue Aug 23 08:43:23 2005
@@ -104,14 +104,14 @@
 #endif
 
 struct cache_enable {
-    const char *url;
+    apr_uri_t url;
     const char *type;
-    apr_size_t urllen;
+    apr_size_t pathlen;
 };
 
 struct cache_disable {
-    const char *url;
-    apr_size_t urllen;
+    apr_uri_t url;
+    apr_size_t pathlen;
 };
 
 /* static information about the local cache */
@@ -257,7 +257,7 @@
 CACHE_DECLARE(char *) ap_cache_generate_name(apr_pool_t *p, int dirlevels, 
                                              int dirlength, 
                                              const char *name);
-CACHE_DECLARE(cache_provider_list *)ap_cache_get_providers(request_rec *r, cache_server_conf
*conf, const char *url);
+CACHE_DECLARE(cache_provider_list *)ap_cache_get_providers(request_rec *r, cache_server_conf
*conf, apr_uri_t uri);
 CACHE_DECLARE(int) ap_cache_liststr(apr_pool_t *p, const char *list,
                                     const char *key, char **val);
 CACHE_DECLARE(const char *)ap_cache_tokstr(apr_pool_t *p, const char *list, const char **str);



Mime
View raw message