]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Merge r504183 from trunk:
authorRuediger Pluem <rpluem@apache.org>
Thu, 17 May 2007 20:57:17 +0000 (20:57 +0000)
committerRuediger Pluem <rpluem@apache.org>
Thu, 17 May 2007 20:57:17 +0000 (20:57 +0000)
* Add CacheIgnoreQueryString directive to cache requests with a query string
  even if no expiration time is specified. Futhermore the query string will not
  be used for key generation such that requests to the same URI path, but with
  different query strings are mapped to the same cache entity. Turning this
  setting to ON violates RFC 2616/13.9 and thus it is turned off by default.

PR: 41484
Submitted by: Fredrik Widlund <fredrik.widlund qbrick.com>
Reviewed by: rpluem, jerenkrantz, jim

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@539111 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
docs/manual/mod/mod_cache.xml
modules/cache/cache_storage.c
modules/cache/mod_cache.c
modules/cache/mod_cache.h

diff --git a/CHANGES b/CHANGES
index bd0bf756c404f06bf3cf286c27b7477e5c359c47..5f1e6843185dd50f116a40a99adb33efba844cd4 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
                                                         -*- coding: utf-8 -*-
 Changes with Apache 2.2.5
 
+  *) mod_cache: Add CacheIgnoreQueryString directive.  PR 41484.
+     [Fredrik Widlund <fredrik.widlund qbrick.com>]
+
   *) mod_cache: While serving a cached entity ensure that filters that have
      been applied to this cached entity before saving it to the cache are not
      applied again. PR 40090. [Ruediger Pluem]
diff --git a/STATUS b/STATUS
index d64a275c6378e210edb8a5abdd3a1d8d043c4f3d..9a6b2bc829cb2be5e89acb1c29a1b5064ef6a6c1 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -129,15 +129,6 @@ PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
          cache during the quick handler phase. If there are still questions
          we should continue the discussion on the list.
 
-   * mod_cache: Add CacheIgnoreQueryString directive to cache requests with
-     a query string even if no expiration time is specified.
-        PR: 41484
-     Trunk version of patch:
-       http://svn.apache.org/viewvc?view=rev&revision=504183
-     2.2.x version of patch:
-       Trunk version works
-     +1: rpluem, jerenkrantz, jim
-
 PATCHES PROPOSED TO BACKPORT FROM TRUNK:
 
     * ApacheMonitor: Fix Windows Vista detection.
index 9a4d4a5f049f037c4809d5acd2793751d6ae0ac5..b98b9b1fa9c90f83c3cf0861051c873c403afaab 100644 (file)
@@ -291,6 +291,31 @@ header.</description>
 <seealso><directive module="mod_cache">CacheStoreNoStore</directive></seealso>
 </directivesynopsis>
 
+<directivesynopsis>
+<name>CacheIgnoreQueryString</name>
+<description>Ignore query string when caching</description>
+<syntax>CacheIgnoreQueryString On|Off</syntax>
+<default>CacheIgnoreQueryString Off</default>
+<contextlist><context>server config</context><context>virtual host</context>
+</contextlist>
+
+<usage>
+    <p>Ordinarily, requests with query string parameters are cached separately
+    for each unique query string. This is according to RFC 2616/13.9 done only
+    if an expiration time is specified. The 
+    <directive>CacheIgnoreQueryString</directive> directive tells the cache to
+    cache requests even if no expiration time is specified, and to reply with 
+    a cached reply even if the query string differs. From a caching point of
+    view the request is treated as if having no query string when this 
+    directive is enabled.</p>
+
+    <example>
+      CacheIgnoreQueryString On
+    </example>
+
+</usage>
+</directivesynopsis>
+
 <directivesynopsis>
 <name>CacheLastModifiedFactor</name>
 <description>The factor used to compute an expiry date based on the
index 460fa3dfd69bec5bf693088a98d0da4258fa9b9f..f396ce8d3a3fceb8c4f49b3077e5f4783992fb67 100644 (file)
@@ -331,10 +331,18 @@ int cache_select(request_rec *r)
 apr_status_t cache_generate_key_default(request_rec *r, apr_pool_t* p,
                                         char**key)
 {
+    cache_server_conf *conf;
     char *port_str, *hn, *lcs;
     const char *hostname, *scheme;
     int i;
 
+    /*
+     * Get the module configuration. We need this for the CacheIgnoreQueryString
+     * option below.
+     */
+    conf = (cache_server_conf *) ap_get_module_config(r->server->module_config,
+                                                      &cache_module);
+
     /*
      * Use the canonical name to improve cache hit rate, but only if this is
      * not a proxy request or if this is a reverse proxy request.
@@ -425,9 +433,15 @@ apr_status_t cache_generate_key_default(request_rec *r, apr_pool_t* p,
         port_str = apr_psprintf(p, ":%u", ap_get_server_port(r));
     }
 
-    /* Key format is a URI */
-    *key = apr_pstrcat(p, scheme, "://", hostname, port_str,
-                       r->parsed_uri.path, "?", r->parsed_uri.query, NULL);
+    /* 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);
+    }
+    else {
+        *key = apr_pstrcat(p, scheme, "://", hostname, port_str,
+                           r->parsed_uri.path, "?", r->parsed_uri.query, NULL);
+    }
 
     return APR_SUCCESS;
 }
index ffee10675dd9434402b05a939850325f91b8b31a..9646b964dadf24453666c686ea7ac15d5b662c44 100644 (file)
@@ -452,7 +452,7 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
         /* if a Expires header is in the past, don't cache it */
         reason = "Expires header already expired, not cacheable";
     }
-    else if (r->parsed_uri.query && exps == NULL) {
+    else if (!conf->ignorequerystring && r->parsed_uri.query && exps == NULL) {
         /* if query string present but no expiration time, don't cache it
          * (RFC 2616/13.9)
          */
@@ -915,6 +915,9 @@ static void * create_cache_config(apr_pool_t *p, server_rec *s)
     /* array of headers that should not be stored in cache */
     ps->ignore_headers = apr_array_make(p, 10, sizeof(char *));
     ps->ignore_headers_set = CACHE_IGNORE_HEADERS_UNSET;
+    /* flag indicating that query-string should be ignored when caching */
+    ps->ignorequerystring = 0;
+    ps->ignorequerystring_set = 0;
     return ps;
 }
 
@@ -960,6 +963,10 @@ static void * merge_cache_config(apr_pool_t *p, void *basev, void *overridesv)
         (overrides->ignore_headers_set == CACHE_IGNORE_HEADERS_UNSET)
         ? base->ignore_headers
         : overrides->ignore_headers;
+    ps->ignorequerystring =
+        (overrides->ignorequerystring_set == 0)
+        ? base->ignorequerystring
+        : overrides->ignorequerystring;
     return ps;
 }
 static const char *set_cache_ignore_no_last_mod(cmd_parms *parms, void *dummy,
@@ -1138,6 +1145,19 @@ static const char *set_cache_factor(cmd_parms *parms, void *dummy,
     return NULL;
 }
 
+static const char *set_cache_ignore_querystring(cmd_parms *parms, void *dummy,
+                                                int flag)
+{
+    cache_server_conf *conf;
+
+    conf =
+        (cache_server_conf *)ap_get_module_config(parms->server->module_config,
+                                                  &cache_module);
+    conf->ignorequerystring = flag;
+    conf->ignorequerystring_set = 1;
+    return NULL;
+}
+
 static int cache_post_config(apr_pool_t *p, apr_pool_t *plog,
                              apr_pool_t *ptemp, server_rec *s)
 {
@@ -1187,6 +1207,9 @@ static const command_rec cache_cmds[] =
     AP_INIT_ITERATE("CacheIgnoreHeaders", add_ignore_header, NULL, RSRC_CONF,
                     "A space separated list of headers that should not be "
                     "stored by the cache"),
+    AP_INIT_FLAG("CacheIgnoreQueryString", set_cache_ignore_querystring,
+                 NULL, RSRC_CONF,
+                 "Ignore query-string when caching"),
     AP_INIT_TAKE1("CacheLastModifiedFactor", set_cache_factor, NULL, RSRC_CONF,
                   "The factor used to estimate Expires date from "
                   "LastModified date"),
index eb5c8cede7b5ce92ff365d09823471f08a8b475e..308a70ab773e772ca652f45af0945484c392cfb6 100644 (file)
@@ -150,6 +150,9 @@ typedef struct {
     #define CACHE_IGNORE_HEADERS_SET   1
     #define CACHE_IGNORE_HEADERS_UNSET 0
     int ignore_headers_set;
+    /** ignore query-string when caching */
+    int ignorequerystring;
+    int ignorequerystring_set;
 } cache_server_conf;
 
 /* cache info information */