From 3b84be8b35136bdea217ea8d5cb6df4b03dd440e Mon Sep 17 00:00:00 2001 From: Brian Pane Date: Sun, 17 Nov 2002 01:33:25 +0000 Subject: [PATCH] When storing the response headers in mod_cache, omit Transfer-Encoding 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 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@97542 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 4 ++++ modules/experimental/cache_util.c | 22 ++++++++++++++++++++++ modules/experimental/mod_cache.h | 5 +++++ modules/experimental/mod_disk_cache.c | 5 +++-- modules/experimental/mod_mem_cache.c | 2 +- 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index c873c98cf4..22163b5772 100644 --- 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 , Brian Pane] + *) mod_cgid: Handle environment variables containing newlines. PR 14550 [Piotr Czejkowski , Jeff Trawick] diff --git a/modules/experimental/cache_util.c b/modules/experimental/cache_util.c index 4d7bc1d5c8..636b9a1bac 100644 --- a/modules/experimental/cache_util.c +++ b/modules/experimental/cache_util.c @@ -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; +} diff --git a/modules/experimental/mod_cache.h b/modules/experimental/mod_cache.h index bfc460e0e1..ca9a8c78af 100644 --- a/modules/experimental/mod_cache.h +++ b/modules/experimental/mod_cache.h @@ -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 */ diff --git a/modules/experimental/mod_disk_cache.c b/modules/experimental/mod_disk_cache.c index d37a3321fc..baba5a299d 100644 --- a/modules/experimental/mod_disk_cache.c +++ b/modules/experimental/mod_disk_cache.c @@ -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); diff --git a/modules/experimental/mod_mem_cache.c b/modules/experimental/mod_mem_cache.c index 0b25c8770a..c6fa6619bd 100644 --- a/modules/experimental/mod_mem_cache.c +++ b/modules/experimental/mod_mem_cache.c @@ -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; } -- 2.40.0