You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rp...@apache.org on 2009/05/21 12:42:54 UTC

svn commit: r777042 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mod_cache.xml modules/cache/cache_storage.c modules/cache/mod_cache.c modules/cache/mod_cache.h

Author: rpluem
Date: Thu May 21 10:42:54 2009
New Revision: 777042

URL: http://svn.apache.org/viewvc?rev=777042&view=rev
Log:
* Add CacheIgnoreURLSessionIdentifiers directive to ignore
  defined session identifiers encoded in the URL when caching.

Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/docs/manual/mod/mod_cache.xml
    httpd/httpd/trunk/modules/cache/cache_storage.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/viewvc/httpd/httpd/trunk/CHANGES?rev=777042&r1=777041&r2=777042&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Thu May 21 10:42:54 2009
@@ -6,6 +6,10 @@
      mod_proxy_ajp: Avoid delivering content from a previous request which
      failed to send a request body. PR 46949 [Ruediger Pluem]
 
+  *) mod_cache: Add CacheIgnoreURLSessionIdentifiers directive to ignore
+     defined session identifiers encoded in the URL when caching.
+     [Ruediger Pluem]
+
   *) mod_rewrite: Fix the error string returned by RewriteRule.
      RewriteRule returned "RewriteCond: bad flag delimiters" when the 3rd
      argument of RewriteRule was not started with "[" or not ended with "]".

Modified: httpd/httpd/trunk/docs/manual/mod/mod_cache.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/mod_cache.xml?rev=777042&r1=777041&r2=777042&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mod_cache.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/mod_cache.xml Thu May 21 10:42:54 2009
@@ -392,6 +392,41 @@
 </directivesynopsis>
 
 <directivesynopsis>
+<name>CacheIgnoreURLSessionIdentifiers</name>
+<description>Ignore defined session identifiers encoded in the URL when caching
+</description>
+<syntax>CacheIgnoreURLSessionIdentifiers <var>identifier</var> [<var>identifier</var>] ...</syntax>
+<default>CacheIgnoreURLSessionIdentifiers None</default>
+<contextlist><context>server config</context><context>virtual host</context>
+</contextlist>
+
+<usage>
+    <p>Sometimes applications encode the session identifier into the URL like in the following
+    Examples:
+    </p>
+    <ul>
+      <li><code>/someapplication/image.gif;jsessionid=123456789</code></li>
+      <li><code>/someapplication/image.gif?PHPSESSIONID=12345678</code></li>
+    </ul>
+    <p>This causes cachable resources to be stored separately for each session, which
+    is often not desired. <directive>CacheIgnoreURLSessionIdentifiers</directive> lets
+    define a list of identifiers that are removed from the key that is used to identify
+    an entity in the cache, such that cachable resources are not stored separately for
+    each session.
+    </p>
+
+    <example><title>Example 1</title>
+      CacheIgnoreURLSessionIdentifiers jsessionid
+    </example>
+
+    <example><title>Example 2</title>
+      CacheIgnoreURLSessionIdentifiers None
+    </example>
+
+</usage>
+</directivesynopsis>
+
+<directivesynopsis>
 <name>CacheStorePrivate</name>
 <description>Attempt to cache responses that the server has marked as private</description>
 <syntax>CacheStorePrivate On|Off</syntax>

Modified: httpd/httpd/trunk/modules/cache/cache_storage.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/cache/cache_storage.c?rev=777042&r1=777041&r2=777042&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/cache/cache_storage.c (original)
+++ httpd/httpd/trunk/modules/cache/cache_storage.c Thu May 21 10:42:54 2009
@@ -355,6 +355,7 @@
     char *port_str, *hn, *lcs;
     const char *hostname, *scheme;
     int i;
+    char *path, *querystring;
 
     cache = (cache_request_rec *) ap_get_module_config(r->request_config,
                                                        &cache_module);
@@ -472,14 +473,65 @@
         port_str = apr_psprintf(p, ":%u", ap_get_server_port(r));
     }
 
+    /*
+     * Check if we need to ignore session identifiers in the URL and do so
+     * if needed.
+     */
+    path = r->parsed_uri.path;
+    querystring = r->parsed_uri.query;
+    if (conf->ignore_session_id_set == CACHE_IGNORE_SESSION_ID_SET) {
+        int i;
+        char **identifier;
+
+        identifier = (char **)conf->ignore_session_id->elts;
+        for (i = 0; i < conf->ignore_session_id->nelts; i++, identifier++) {
+            int len;
+            char *param;
+
+            len = strlen(*identifier);
+            /*
+             * Check that we have a parameter separator in the last segment
+             * of the path and that the parameter matches our identifier
+             */
+            if ((param = strrchr(path, ';'))
+                && !strncmp(param + 1, *identifier, len)
+                && (*(param + len + 1) == '=')
+                && !strchr(param + len + 2, '/')) {
+                path = apr_pstrndup(p, path, param - path);
+                break;
+            }
+            /*
+             * Check if the identifier is in the querystring and cut it out.
+             */
+            if (querystring
+                && (param = strstr(querystring, *identifier))
+                && (*(param + len) == '=')
+                ) {
+                char *amp;
+
+                if (querystring != param) {
+                    querystring = apr_pstrndup(p, querystring,
+                                               param - querystring);
+                }
+                else {
+                    querystring = "";
+                }
+                if ((amp = strchr(param + len + 1, '&'))) {
+                    querystring = apr_pstrcat(p, querystring, amp + 1, NULL);
+                }
+                break;
+            }
+        }
+    }
+
     /* Key format is a URI, optionally without the query-string */
     if (conf->ignorequerystring) {
         *key = apr_pstrcat(p, scheme, "://", hostname, port_str,
-                           r->parsed_uri.path, "?", NULL);
+                           path, "?", NULL);
     }
     else {
         *key = apr_pstrcat(p, scheme, "://", hostname, port_str,
-                           r->parsed_uri.path, "?", r->parsed_uri.query, NULL);
+                           path, "?", querystring, NULL);
     }
 
     /*
@@ -491,6 +543,9 @@
      * handler during following requests.
      */
     cache->key = apr_pstrdup(r->pool, *key);
+    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
+                 "cache: Key for entity %s?%s is %s", r->parsed_uri.path,
+                 r->parsed_uri.query, *key);
 
     return APR_SUCCESS;
 }

Modified: httpd/httpd/trunk/modules/cache/mod_cache.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/cache/mod_cache.c?rev=777042&r1=777041&r2=777042&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/cache/mod_cache.c (original)
+++ httpd/httpd/trunk/modules/cache/mod_cache.c Thu May 21 10:42:54 2009
@@ -952,6 +952,9 @@
     /* flag indicating that query-string should be ignored when caching */
     ps->ignorequerystring = 0;
     ps->ignorequerystring_set = 0;
+    /* array of identifiers that should not be used for key calculation */
+    ps->ignore_session_id = apr_array_make(p, 10, sizeof(char *));
+    ps->ignore_session_id_set = CACHE_IGNORE_SESSION_ID_UNSET;
     return ps;
 }
 
@@ -1002,6 +1005,10 @@
         (overrides->ignorequerystring_set == 0)
         ? base->ignorequerystring
         : overrides->ignorequerystring;
+    ps->ignore_session_id =
+        (overrides->ignore_session_id_set == CACHE_IGNORE_HEADERS_UNSET)
+        ? base->ignore_session_id
+        : overrides->ignore_session_id;
     return ps;
 }
 static const char *set_cache_ignore_no_last_mod(cmd_parms *parms, void *dummy,
@@ -1085,6 +1092,34 @@
     return NULL;
 }
 
+static const char *add_ignore_session_id(cmd_parms *parms, void *dummy,
+                                         const char *identifier)
+{
+    cache_server_conf *conf;
+    char **new;
+
+    conf =
+        (cache_server_conf *)ap_get_module_config(parms->server->module_config,
+                                                  &cache_module);
+    if (!strncasecmp(identifier, "None", 4)) {
+        /* if identifier None is listed clear array */
+        conf->ignore_session_id->nelts = 0;
+    }
+    else {
+        if ((conf->ignore_session_id_set == CACHE_IGNORE_SESSION_ID_UNSET) ||
+            (conf->ignore_session_id->nelts)) {
+            /*
+             * Only add identifier if no "None" has been found in identifier
+             * list so far.
+             */
+            new = (char **)apr_array_push(conf->ignore_session_id);
+            (*new) = (char *)identifier;
+        }
+    }
+    conf->ignore_session_id_set = CACHE_IGNORE_SESSION_ID_SET;
+    return NULL;
+}
+
 static const char *add_cache_enable(cmd_parms *parms, void *dummy,
                                     const char *type,
                                     const char *url)
@@ -1260,6 +1295,10 @@
     AP_INIT_FLAG("CacheIgnoreQueryString", set_cache_ignore_querystring,
                  NULL, RSRC_CONF,
                  "Ignore query-string when caching"),
+    AP_INIT_ITERATE("CacheIgnoreURLSessionIdentifiers", add_ignore_session_id,
+                    NULL, RSRC_CONF, "A space separated list of session "
+                    "identifiers that should be ignored for creating the key "
+                    "of the cached entity."),
     AP_INIT_TAKE1("CacheLastModifiedFactor", set_cache_factor, NULL, RSRC_CONF,
                   "The factor used to estimate Expires date from "
                   "LastModified date"),

Modified: httpd/httpd/trunk/modules/cache/mod_cache.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/cache/mod_cache.h?rev=777042&r1=777041&r2=777042&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/cache/mod_cache.h (original)
+++ httpd/httpd/trunk/modules/cache/mod_cache.h Thu May 21 10:42:54 2009
@@ -155,6 +155,12 @@
     /** ignore query-string when caching */
     int ignorequerystring;
     int ignorequerystring_set;
+    /** store the identifiers that should not be used for key calculation */
+    apr_array_header_t *ignore_session_id;
+    /* flag if CacheIgnoreURLSessionIdentifiers has been set */
+    #define CACHE_IGNORE_SESSION_ID_SET   1
+    #define CACHE_IGNORE_SESSION_ID_UNSET 0
+    int ignore_session_id_set;
 } cache_server_conf;
 
 /* cache info information */



Re: svn commit: r777042 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mod_cache.xml modules/cache/cache_storage.c modules/cache/mod_cache.c modules/cache/mod_cache.h

Posted by Ruediger Pluem <rp...@apache.org>.

On 09/26/2009 11:46 PM, Jeff Trawick wrote:
> On Thu, May 21, 2009 at 6:42 AM, <rp...@apache.org> wrote:
> 
>> Author: rpluem
>> Date: Thu May 21 10:42:54 2009
>> New Revision: 777042
>>
>> URL: http://svn.apache.org/viewvc?rev=777042&view=rev
>> Log:
>> * Add CacheIgnoreURLSessionIdentifiers directive to ignore
>>  defined session identifiers encoded in the URL when caching.
>>
>> Modified:
>>    httpd/httpd/trunk/CHANGES
>>    httpd/httpd/trunk/docs/manual/mod/mod_cache.xml
>>    httpd/httpd/trunk/modules/cache/cache_storage.c
>>    httpd/httpd/trunk/modules/cache/mod_cache.c
>>    httpd/httpd/trunk/modules/cache/mod_cache.h
>>
>> Modified: httpd/httpd/trunk/modules/cache/mod_cache.c

>> +                                                  &cache_module);
>> +    if (!strncasecmp(identifier, "None", 4)) {
>> +        /* if identifier None is listed clear array */
>> +        conf->ignore_session_id->nelts = 0;
>>
> 
> This should be strcasecmp() since the entire parameter has to be "None", no?

Make sense. Fixed in r819237.

Regards

Rüdiger

Re: svn commit: r777042 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mod_cache.xml modules/cache/cache_storage.c modules/cache/mod_cache.c modules/cache/mod_cache.h

Posted by Jeff Trawick <tr...@gmail.com>.
On Thu, May 21, 2009 at 6:42 AM, <rp...@apache.org> wrote:

> Author: rpluem
> Date: Thu May 21 10:42:54 2009
> New Revision: 777042
>
> URL: http://svn.apache.org/viewvc?rev=777042&view=rev
> Log:
> * Add CacheIgnoreURLSessionIdentifiers directive to ignore
>  defined session identifiers encoded in the URL when caching.
>
> Modified:
>    httpd/httpd/trunk/CHANGES
>    httpd/httpd/trunk/docs/manual/mod/mod_cache.xml
>    httpd/httpd/trunk/modules/cache/cache_storage.c
>    httpd/httpd/trunk/modules/cache/mod_cache.c
>    httpd/httpd/trunk/modules/cache/mod_cache.h
>
> Modified: httpd/httpd/trunk/modules/cache/mod_cache.c
> URL:
> http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/cache/mod_cache.c?rev=777042&r1=777041&r2=777042&view=diff
>
> ==============================================================================
> --- httpd/httpd/trunk/modules/cache/mod_cache.c (original)
> +++ httpd/httpd/trunk/modules/cache/mod_cache.c Thu May 21 10:42:54 2009
> @@ -952,6 +952,9 @@
>     /* flag indicating that query-string should be ignored when caching */
>     ps->ignorequerystring = 0;
>     ps->ignorequerystring_set = 0;
> +    /* array of identifiers that should not be used for key calculation */
> +    ps->ignore_session_id = apr_array_make(p, 10, sizeof(char *));
> +    ps->ignore_session_id_set = CACHE_IGNORE_SESSION_ID_UNSET;
>     return ps;
>  }
>
> @@ -1002,6 +1005,10 @@
>         (overrides->ignorequerystring_set == 0)
>         ? base->ignorequerystring
>         : overrides->ignorequerystring;
> +    ps->ignore_session_id =
> +        (overrides->ignore_session_id_set == CACHE_IGNORE_HEADERS_UNSET)
> +        ? base->ignore_session_id
> +        : overrides->ignore_session_id;
>     return ps;
>  }
>  static const char *set_cache_ignore_no_last_mod(cmd_parms *parms, void
> *dummy,
> @@ -1085,6 +1092,34 @@
>     return NULL;
>  }
>
> +static const char *add_ignore_session_id(cmd_parms *parms, void *dummy,
> +                                         const char *identifier)
> +{
> +    cache_server_conf *conf;
> +    char **new;
> +
> +    conf =
> +        (cache_server_conf
> *)ap_get_module_config(parms->server->module_config,
> +                                                  &cache_module);
> +    if (!strncasecmp(identifier, "None", 4)) {
> +        /* if identifier None is listed clear array */
> +        conf->ignore_session_id->nelts = 0;
>

This should be strcasecmp() since the entire parameter has to be "None", no?

Re: svn commit: r777042 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mod_cache.xml modules/cache/cache_storage.c modules/cache/mod_cache.c modules/cache/mod_cache.h

Posted by "Plüm, Rüdiger, VF-Group" <ru...@vodafone.com>.
 

> -----Ursprüngliche Nachricht-----
> Von: Dan Poirier 
> Gesendet: Donnerstag, 21. Mai 2009 14:07
> An: dev@httpd.apache.org
> Betreff: Re: svn commit: r777042 - in /httpd/httpd/trunk: 
> CHANGES docs/manual/mod/mod_cache.xml 
> modules/cache/cache_storage.c modules/cache/mod_cache.c 
> modules/cache/mod_cache.h
> 
> Suggestion:
> 
> Index: docs/manual/mod/mod_cache.xml
> ===================================================================
> --- docs/manual/mod/mod_cache.xml	(revision 777086)
> +++ docs/manual/mod/mod_cache.xml	(working copy)
> @@ -414,6 +414,8 @@
>      an entity in the cache, such that cachable resources are 
> not stored separately for
>      each session.
>      </p>
> +    <p><code>CacheIgnoreURLSessionIdentifiers None</code> 
> clears the list of ignored
> +    identifiers.  Otherwise, each identifier is added to the 
> list.</p>
>  
>      <example><title>Example 1</title>
>        CacheIgnoreURLSessionIdentifiers jsessionid
> 

Thanks for the proposal. Committed in r777091.

Regards

Rüdiger

Re: svn commit: r777042 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mod_cache.xml modules/cache/cache_storage.c modules/cache/mod_cache.c modules/cache/mod_cache.h

Posted by Dan Poirier <po...@pobox.com>.
Suggestion:

Index: docs/manual/mod/mod_cache.xml
===================================================================
--- docs/manual/mod/mod_cache.xml	(revision 777086)
+++ docs/manual/mod/mod_cache.xml	(working copy)
@@ -414,6 +414,8 @@
     an entity in the cache, such that cachable resources are not stored separately for
     each session.
     </p>
+    <p><code>CacheIgnoreURLSessionIdentifiers None</code> clears the list of ignored
+    identifiers.  Otherwise, each identifier is added to the list.</p>
 
     <example><title>Example 1</title>
       CacheIgnoreURLSessionIdentifiers jsessionid



-- 
Dan Poirier <po...@pobox.com>