httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r1595916 - in /httpd/httpd/branches/2.4.x: ./ STATUS modules/cache/mod_cache.c
Date Mon, 19 May 2014 14:51:36 GMT
Author: jim
Date: Mon May 19 14:51:35 2014
New Revision: 1595916

URL: http://svn.apache.org/r1595916
Log:
Merge r1591320, r1591322, r1591390, r1591394 from trunk:

mod_cache: Don't add cached/revalidated entity headers to a 304 response.
           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.


mod_cache: follow up to r1591320.

Use the new MOD_CACHE_ENTITY_HEADERS[] names to check 304 contradictions
against the same headers.


mod_cache: follow up to r1591322

Avoid one unnecessary test when checking 304 contradictions.


mod_cache: follow up to r1591390

Fix code typo.

Submitted by: ylavic
Reviewed/backported by: jim

Modified:
    httpd/httpd/branches/2.4.x/   (props changed)
    httpd/httpd/branches/2.4.x/STATUS
    httpd/httpd/branches/2.4.x/modules/cache/mod_cache.c

Propchange: httpd/httpd/branches/2.4.x/
------------------------------------------------------------------------------
  Merged /httpd/httpd/trunk:r1591320,1591322,1591390,1591394

Modified: httpd/httpd/branches/2.4.x/STATUS
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/STATUS?rev=1595916&r1=1595915&r2=1595916&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/STATUS (original)
+++ httpd/httpd/branches/2.4.x/STATUS Mon May 19 14:51:35 2014
@@ -100,15 +100,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
-   * mod_cache: Don't add cached/revalidated entity headers to a 304 response.
-                PR 55547.
-     trunk patch: http://svn.apache.org/r1591320
-                  http://svn.apache.org/r1591322
-                  http://svn.apache.org/r1591390
-                  http://svn.apache.org/r1591394
-     2.4.x patch: http://people.apache.org/~ylavic/httpd-2.4.x-mod_cache-strip_304_entity_headers.patch
-     +1: ylavic, jim, minfrin
-
    * 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].

Modified: httpd/httpd/branches/2.4.x/modules/cache/mod_cache.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/cache/mod_cache.c?rev=1595916&r1=1595915&r2=1595916&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/cache/mod_cache.c (original)
+++ httpd/httpd/branches/2.4.x/modules/cache/mod_cache.c Mon May 19 14:51:35 2014
@@ -36,6 +36,22 @@ static ap_filter_rec_t *cache_out_subreq
 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
  * -------------
@@ -756,17 +772,16 @@ static int cache_save_store(ap_filter_t 
 /**
  * Sanity check for 304 Not Modified responses, as per RFC2616 Section 10.3.5.
  */
-static const char *cache_header_cmp(apr_pool_t *pool, apr_table_t *left,
+static int cache_header_cmp(apr_pool_t *pool, apr_table_t *left,
         apr_table_t *right, const char *key)
 {
     const char *h1, *h2;
 
     if ((h1 = cache_table_getm(pool, left, key))
             && (h2 = cache_table_getm(pool, right, key)) && (strcmp(h1, h2)))
{
-        return apr_pstrcat(pool, "contradiction: 304 Not Modified, but ", key,
-                " modified", NULL);
+        return 1;
     }
-    return NULL;
+    return 0;
 }
 
 /*
@@ -802,7 +817,7 @@ static apr_status_t cache_save_filter(ap
     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;
@@ -1111,29 +1126,22 @@ static apr_status_t cache_save_filter(ap
     else if (r->status == HTTP_NOT_MODIFIED && cache->stale_handle) {
         apr_table_t *left = cache->stale_handle->resp_hdrs;
         apr_table_t *right = r->headers_out;
+        const char *ehs = NULL;
 
         /* and lastly, contradiction checks for revalidated responses
          * as per RFC2616 Section 10.3.5
          */
-        if (((reason = cache_header_cmp(r->pool, left, right, "Allow")))
-                || ((reason = cache_header_cmp(r->pool, left, right,
-                        "Content-Encoding")))
-                || ((reason = cache_header_cmp(r->pool, left, right,
-                        "Content-Language")))
-                || ((reason = cache_header_cmp(r->pool, left, right,
-                        "Content-Length")))
-                || ((reason = cache_header_cmp(r->pool, left, right,
-                        "Content-Location")))
-                || ((reason = cache_header_cmp(r->pool, left, right,
-                        "Content-MD5")))
-                || ((reason = cache_header_cmp(r->pool, left, right,
-                        "Content-Range")))
-                || ((reason = cache_header_cmp(r->pool, left, right,
-                        "Content-Type")))
-                || ((reason = cache_header_cmp(r->pool, left, right, "ETag")))
-                || ((reason = cache_header_cmp(r->pool, left, right,
-                        "Last-Modified")))) {
-            /* contradiction: 304 Not Modified, but entity header modified */
+        if (cache_header_cmp(r->pool, left, right, "ETag")) {
+            ehs = "ETag";
+        }
+        for (eh = MOD_CACHE_ENTITY_HEADERS; *eh; ++eh) {
+            if (cache_header_cmp(r->pool, left, right, *eh)) {
+                ehs = (ehs) ? apr_pstrcat(r->pool, ehs, ", ", *eh, NULL) : *eh;
+            }
+        }
+        if (ehs) {
+            reason = apr_pstrcat(r->pool, "contradiction: 304 Not Modified; "
+                                 "but ", ehs, " modified", NULL);
         }
     }
 
@@ -1148,14 +1156,9 @@ static apr_status_t cache_save_filter(ap
      * 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
@@ -1492,6 +1495,13 @@ static apr_status_t cache_save_filter(ap
         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);
         }



Mime
View raw message