]> granicus.if.org Git - apache/commitdiff
mod_cache: Correctly handle HEAD requests on expired cache content. PR 41230.
authorJustin Erenkrantz <jerenkrantz@apache.org>
Fri, 18 May 2007 22:38:08 +0000 (22:38 +0000)
committerJustin Erenkrantz <jerenkrantz@apache.org>
Fri, 18 May 2007 22:38:08 +0000 (22:38 +0000)
* modules/cache/mod_cache.c
  (cache_save_filter): Properly handle HEAD responses when we have a stale handle.

(This patch was revised by Justin/Ruediger.)

Submitted by: Niklas Edmundsson
Reviewed by: Justin, Ruediger

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@539620 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
modules/cache/mod_cache.c

diff --git a/CHANGES b/CHANGES
index 697f26da2f08e011e44f4898435ac483378c7769..d362c14a82e64aeea7b46bb05a269145f89433ea 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,9 @@
 Changes with Apache 2.3.0
   [Remove entries to the current 2.0 and 2.2 section below, when backported]
 
+  *) mod_cache: Correctly handle HEAD requests on expired cache content.
+     PR 41230.  [Niklas Edmundsson]
+
   *) mod_proxy: Added ProxyPassMatch directive, which is similar
      to ProxyPass but takes a regex local path prefix. [Jim Jagielski]
 
index 6f4170a36bd707ac3184069eff7d471d3be887b2..19afb35de581e9a589bc46790c007ee040fa178a 100644 (file)
@@ -476,8 +476,8 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
          */
         reason = "No Last-Modified, Etag, or Expires headers";
     }
-    else if (r->header_only) {
-        /* HEAD requests */
+    else if (r->header_only && !cache->stale_handle) {
+        /* Forbid HEAD requests unless we have it cached already */
         reason = "HTTP HEAD request";
     }
     else if (!conf->store_nostore &&
@@ -596,7 +596,12 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
      * the headers).
      */
 
-    /* Did we have a stale cache entry that really is stale? */
+    /* Did we have a stale cache entry that really is stale?
+     *
+     * Note that for HEAD requests, we won't get the body, so for a stale
+     * HEAD request, we don't remove the entity - instead we let the
+     * CACHE_REMOVE_URL filter remove the stale item from the cache.
+     */
     if (cache->stale_handle) {
         if (r->status == HTTP_NOT_MODIFIED) {
             /* Oh, hey.  It isn't that stale!  Yay! */
@@ -604,7 +609,7 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
             info = &cache->handle->cache_obj->info;
             rv = OK;
         }
-        else {
+        else if (!r->header_only) {
             /* Oh, well.  Toss it. */
             cache->provider->remove_entity(cache->stale_handle);
             /* Treat the request as if it wasn't conditional. */
@@ -612,8 +617,8 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
         }
     }
 
-    /* no cache handle, create a new entity */
-    if (!cache->handle) {
+    /* no cache handle, create a new entity only for non-HEAD requests */
+    if (!cache->handle && !r->header_only) {
         rv = cache_create_entity(r, size);
         info = apr_pcalloc(r->pool, sizeof(cache_info));
         /* We only set info->status upon the initial creation. */