From baf4f92af0f97d8bc72460446d2384d849ae0cf3 Mon Sep 17 00:00:00 2001 From: Yann Ylavic Date: Wed, 14 May 2014 17:11:49 +0000 Subject: mod_cache: follow up to r1591328. Define the cache_merge_headers_out() function to merge r->err_headers_out into r->headers_out and add the ones from r->content_type/encoding if available. Use it in ap_cache_cacheable_headers_out() where the same is done and in cache_save_filter() where this has to be done before updating the entry. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1594643 13f79535-47bb-0310-9956-ffa450edef68 --- modules/cache/cache_util.c | 25 ++++++++++++++++--------- modules/cache/cache_util.h | 6 ++++++ modules/cache/mod_cache.c | 4 +--- 3 files changed, 23 insertions(+), 12 deletions(-) (limited to 'modules/cache') diff --git a/modules/cache/cache_util.c b/modules/cache/cache_util.c index cafbc16781..05cd3e09c9 100644 --- a/modules/cache/cache_util.c +++ b/modules/cache/cache_util.c @@ -1237,26 +1237,33 @@ CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_headers_out(request_rec *r) { apr_table_t *headers_out; - headers_out = apr_table_overlay(r->pool, r->headers_out, - r->err_headers_out); - - apr_table_clear(r->err_headers_out); - - headers_out = ap_cache_cacheable_headers(r->pool, headers_out, - r->server); + headers_out = ap_cache_cacheable_headers(r->pool, + cache_merge_headers_out(r), + r->server); cache_control_remove(r, cache_table_getm(r->pool, headers_out, "Cache-Control"), headers_out); + return headers_out; +} + +apr_table_t *cache_merge_headers_out(request_rec *r) +{ + apr_table_t *headers_out; + + headers_out = apr_table_overlay(r->pool, r->headers_out, + r->err_headers_out); + apr_table_clear(r->err_headers_out); + if (!apr_table_get(headers_out, "Content-Type") - && r->content_type) { + && r->content_type) { apr_table_setn(headers_out, "Content-Type", ap_make_content_type(r, r->content_type)); } if (!apr_table_get(headers_out, "Content-Encoding") - && r->content_encoding) { + && r->content_encoding) { apr_table_setn(headers_out, "Content-Encoding", r->content_encoding); } diff --git a/modules/cache/cache_util.h b/modules/cache/cache_util.h index 37c3ac3242..b845d2d27d 100644 --- a/modules/cache/cache_util.h +++ b/modules/cache/cache_util.h @@ -321,6 +321,12 @@ const char *cache_table_getm(apr_pool_t *p, const apr_table_t *t, */ char *cache_strqtok(char *str, const char *sep, char **last); +/** + * Merge err_headers_out into headers_out and add request's Content-Type and + * Content-Encoding if available. + */ +apr_table_t *cache_merge_headers_out(request_rec *r); + #ifdef __cplusplus } #endif diff --git a/modules/cache/mod_cache.c b/modules/cache/mod_cache.c index afa1980515..93bb9f7828 100644 --- a/modules/cache/mod_cache.c +++ b/modules/cache/mod_cache.c @@ -1449,9 +1449,7 @@ static apr_status_t cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in) * here we want to keep the original headers in r->headers_out and * forward all of them to the client, including non-cacheable ones). */ - r->headers_out = apr_table_overlay(r->pool, r->headers_out, - r->err_headers_out); - apr_table_clear(r->err_headers_out); + r->headers_out = cache_merge_headers_out(r); /* Merge in our cached headers. However, keep any updated values. */ /* take output, overlay on top of cached */ -- cgit v1.2.3