]> granicus.if.org Git - apache/commitdiff
When storing the response headers in mod_cache, omit Transfer-Encoding
authorBrian Pane <brianp@apache.org>
Sun, 17 Nov 2002 01:33:25 +0000 (01:33 +0000)
committerBrian Pane <brianp@apache.org>
Sun, 17 Nov 2002 01:33:25 +0000 (01:33 +0000)
and any other hop-by-hop headers that shouldn't be applied when the
response is later delivered from cache:
http://marc.theaimsgroup.com/?l=apache-httpd-dev&m=103727389213072
Diagnosed by: Estrade Matthieu <estrade-m@ifrance.com>

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

CHANGES
modules/experimental/cache_util.c
modules/experimental/mod_cache.h
modules/experimental/mod_disk_cache.c
modules/experimental/mod_mem_cache.c

diff --git a/CHANGES b/CHANGES
index c873c98cf4e274fd34b82a7b7eb05f4d9a067930..22163b577238f3cc03d6be5eca2085aa14af8995 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,9 @@
 Changes with Apache 2.0.44
 
+  *) mod_cache: Don't cache response header fields designated
+     as hop-by-hop headers in HTTP/1.1 (RFC 2616 Section 13.5.1).
+     [Estrade Matthieu <estrade-m@ifrance.com>, Brian Pane]
+
   *) mod_cgid: Handle environment variables containing newlines.
      PR 14550  [Piotr Czejkowski <apache@czarny.eu.org>, Jeff
      Trawick]
index 4d7bc1d5c863e42b7c5d5c58ed0b606092b077bf..636b9a1bace36932f9862dbdba9b3b0125468754 100644 (file)
@@ -469,3 +469,25 @@ CACHE_DECLARE(char *)generate_name(apr_pool_t *p, int dirlevels, int dirlength,
     cache_hash(name, hashfile, dirlevels, dirlength);
     return apr_pstrdup(p, hashfile);
 }
+
+/* Create a new table consisting of those elements from a request_rec's
+ * headers_out that are allowed to be stored in a cache.
+ */
+CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_hdrs_out(request_rec *r)
+{
+    /* Make a copy of the response headers, and remove from
+     * the copy any hop-by-hop headers, as defined in Section
+     * 13.5.1 of RFC 2616
+     */
+    apr_table_t *headers_out;
+    headers_out = apr_table_copy(r->pool, r->headers_out);
+    apr_table_unset(headers_out, "Connection");
+    apr_table_unset(headers_out, "Keep-Alive");
+    apr_table_unset(headers_out, "Proxy-Authenticate");
+    apr_table_unset(headers_out, "Proxy-Authorization");
+    apr_table_unset(headers_out, "TE");
+    apr_table_unset(headers_out, "Trailers");
+    apr_table_unset(headers_out, "Transfer-Encoding");
+    apr_table_unset(headers_out, "Upgrade");
+    return headers_out;
+}
index bfc460e0e17fc916bb3c03affe2a46d4d2d4a7cd..ca9a8c78af04329b3df6ad72bb4956e4cbe892d8 100644 (file)
@@ -279,6 +279,11 @@ CACHE_DECLARE(int) ap_cache_liststr(apr_pool_t *p, const char *list,
                                     const char *key, char **val);
 CACHE_DECLARE(const char *)ap_cache_tokstr(apr_pool_t *p, const char *list, const char **str);
 
+/* Create a new table consisting of those elements from a request_rec's
+ * headers_out that are allowed to be stored in a cache
+ */
+CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_hdrs_out(request_rec *r);
+
 /**
  * cache_storage.c
  */
index d37a3321fc9f5be5e3910a41c4ef688511acafb5..baba5a299da6eec29a9c33bbb58c47c570b0b89e 100644 (file)
@@ -603,8 +603,9 @@ static apr_status_t write_headers(cache_handle_t *h, request_rec *r, cache_info
 
         if (r->headers_out) {
             int i;
-            apr_table_entry_t *elts = (apr_table_entry_t *) apr_table_elts(r->headers_out)->elts;
-            for (i = 0; i < apr_table_elts(r->headers_out)->nelts; ++i) {
+            apr_table_t* headers_out = ap_cache_cacheable_hdrs_out(r);
+            apr_table_entry_t *elts = (apr_table_entry_t *) apr_table_elts(headers_out)->elts;
+            for (i = 0; i < apr_table_elts(headers_out)->nelts; ++i) {
                 if (elts[i].key != NULL) {
                     buf = apr_pstrcat(r->pool, elts[i].key, ": ",  elts[i].val, CRLF, NULL);
                     amt = strlen(buf);
index 0b25c8770a0b3ba7039492e640490a9c774d42eb..c6fa6619bd8132ea0b2bc756b860d5ce3159f90e 100644 (file)
@@ -840,7 +840,7 @@ static apr_status_t write_headers(cache_handle_t *h, request_rec *r, cache_info
     /* Precompute how much storage we need to hold the headers */
     rc = serialize_table(&mobj->header_out, 
                          &mobj->num_header_out, 
-                         r->headers_out);   
+                         ap_cache_cacheable_hdrs_out(r));   
     if (rc != APR_SUCCESS) {
         return rc;
     }