]> granicus.if.org Git - apache/commitdiff
mod_cache: Don't add cached/revalidated entity headers to a 304 response.
authorYann Ylavic <ylavic@apache.org>
Wed, 30 Apr 2014 14:43:27 +0000 (14:43 +0000)
committerYann Ylavic <ylavic@apache.org>
Wed, 30 Apr 2014 14:43:27 +0000 (14:43 +0000)
           PR 55547.

When the conditional request meets the conditions of the stale then revalidated
entry, the forwarded 304 response includes the entity headers merged from the
cached headers (before updating the entry).
Strip them before returning a 304.

Since the entity headers are stripped elsewhere, factorize the code using a
new table (MOD_CACHE_ENTITY_HEADERS[]) containing these headers's names.

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

CHANGES
modules/cache/mod_cache.c

diff --git a/CHANGES b/CHANGES
index 9a1b0c0ce482e640116a11f1d014ddc6234649d0..0eafe9dc38b49800b40e55f34e63a6e3a6a9b448 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.5.0
 
+  *) mod_cache: Don't add cached/revalidated entity headers to a 304 response.
+                PR 55547. [Yann Ylavic]
+
   *) mod_cache: Retry unconditional request with the full URL (including the
      query-string) when the origin server's 304 response does not match the
      conditions used to revalidate the stale entry.  [Yann Ylavic].
index af8889a8921cac8d6323af90f1820a44dd6f0ea3..6908a0a23218d786952ff0a5a1b8f5d03305b1b0 100644 (file)
@@ -36,6 +36,22 @@ static ap_filter_rec_t *cache_out_subreq_filter_handle;
 static ap_filter_rec_t *cache_remove_url_filter_handle;
 static ap_filter_rec_t *cache_invalidate_filter_handle;
 
+/**
+ * Entity headers' names
+ */
+static const char *MOD_CACHE_ENTITY_HEADERS[] = {
+    "Allow",
+    "Content-Encoding",
+    "Content-Language",
+    "Content-Length",
+    "Content-Location",
+    "Content-MD5",
+    "Content-Range",
+    "Content-Type",
+    "Last-Modified",
+    NULL
+};
+
 /*
  * CACHE handler
  * -------------
@@ -802,7 +818,7 @@ static apr_status_t cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
     apr_time_t exp, date, lastmod, now;
     apr_off_t size = -1;
     cache_info *info = NULL;
-    const char *reason;
+    const char *reason, **eh;
     apr_pool_t *p;
     apr_bucket *e;
     apr_table_t *headers;
@@ -1150,14 +1166,9 @@ static apr_status_t cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
      * inconsistencies between cached entity-bodies and updated headers.
      */
     if (r->status == HTTP_NOT_MODIFIED) {
-        apr_table_unset(r->headers_out, "Allow");
-        apr_table_unset(r->headers_out, "Content-Encoding");
-        apr_table_unset(r->headers_out, "Content-Language");
-        apr_table_unset(r->headers_out, "Content-Length");
-        apr_table_unset(r->headers_out, "Content-MD5");
-        apr_table_unset(r->headers_out, "Content-Range");
-        apr_table_unset(r->headers_out, "Content-Type");
-        apr_table_unset(r->headers_out, "Last-Modified");
+        for (eh = MOD_CACHE_ENTITY_HEADERS; *eh; ++eh) {
+            apr_table_unset(r->headers_out, *eh);
+        }
     }
 
     /* Hold the phone. Some servers might allow us to cache a 2xx, but
@@ -1494,6 +1505,13 @@ static apr_status_t cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in)
         if (status != OK) {
             r->status = status;
 
+            /* Strip the entity headers merged from the cached headers before
+             * updating the entry (see cache_accept_headers() above).
+             */
+            for (eh = MOD_CACHE_ENTITY_HEADERS; *eh; ++eh) {
+                apr_table_unset(r->headers_out, *eh);
+            }
+
             bkt = apr_bucket_flush_create(bb->bucket_alloc);
             APR_BRIGADE_INSERT_TAIL(bb, bkt);
         }