diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/experimental/cache_util.c | 19 | ||||
-rw-r--r-- | modules/experimental/mod_cache.c | 38 | ||||
-rw-r--r-- | modules/experimental/mod_cache.h | 10 | ||||
-rw-r--r-- | modules/experimental/mod_disk_cache.c | 6 | ||||
-rw-r--r-- | modules/experimental/mod_mem_cache.c | 7 |
5 files changed, 74 insertions, 6 deletions
diff --git a/modules/experimental/cache_util.c b/modules/experimental/cache_util.c index 9ee9f84c9a..7c7dc59395 100644 --- a/modules/experimental/cache_util.c +++ b/modules/experimental/cache_util.c @@ -21,6 +21,8 @@ /* -------------------------------------------------------------- */ +extern module AP_MODULE_DECLARE_DATA cache_module; + /* return true if the request is conditional */ CACHE_DECLARE(int) ap_cache_request_is_conditional(apr_table_t *table) { @@ -517,8 +519,13 @@ CACHE_DECLARE(char *)generate_name(apr_pool_t *p, int dirlevels, * headers table that are allowed to be stored in a cache. */ CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_hdrs_out(apr_pool_t *pool, - apr_table_t *t) + apr_table_t *t, + server_rec *s) { + cache_server_conf *conf; + char **header; + int i; + /* Make a copy of the headers, and remove from * the copy any hop-by-hop headers, as defined in Section * 13.5.1 of RFC 2616 @@ -533,5 +540,15 @@ CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_hdrs_out(apr_pool_t *pool, apr_table_unset(headers_out, "Trailers"); apr_table_unset(headers_out, "Transfer-Encoding"); apr_table_unset(headers_out, "Upgrade"); + + conf = (cache_server_conf *)ap_get_module_config(s->module_config, + &cache_module); + /* Remove the user defined headers set with CacheIgnoreHeaders. + * This may break RFC 2616 compliance on behalf of the administrator. + */ + header = (char **)conf->ignore_headers->elts; + for (i = 0; i < conf->ignore_headers->nelts; i++) { + apr_table_unset(headers_out, header[i]); + } return headers_out; } diff --git a/modules/experimental/mod_cache.c b/modules/experimental/mod_cache.c index b2a6fcd8ee..1836170fae 100644 --- a/modules/experimental/mod_cache.c +++ b/modules/experimental/mod_cache.c @@ -709,6 +709,9 @@ static void * create_cache_config(apr_pool_t *p, server_rec *s) ps->no_last_mod_ignore = 0; ps->ignorecachecontrol = 0; ps->ignorecachecontrol_set = 0 ; + /* array of headers that should not be stored in cache */ + ps->ignore_headers = apr_array_make(p, 10, sizeof(char *)); + ps->ignore_headers_set = CACHE_IGNORE_HEADERS_UNSET; return ps; } @@ -745,6 +748,10 @@ static void * merge_cache_config(apr_pool_t *p, void *basev, void *overridesv) (overrides->ignorecachecontrol_set == 0) ? base->ignorecachecontrol : overrides->ignorecachecontrol; + ps->ignore_headers = + (overrides->ignore_headers_set == CACHE_IGNORE_HEADERS_UNSET) + ? base->ignore_headers + : overrides->ignore_headers; return ps; } static const char *set_cache_ignore_no_last_mod(cmd_parms *parms, void *dummy, @@ -774,6 +781,34 @@ static const char *set_cache_ignore_cachecontrol(cmd_parms *parms, return NULL; } +static const char *add_ignore_header(cmd_parms *parms, void *dummy, + const char *header) +{ + cache_server_conf *conf; + char **new; + + conf = + (cache_server_conf *)ap_get_module_config(parms->server->module_config, + &cache_module); + if (!strncasecmp(header, "None", 4)) { + /* if header None is listed clear array */ + conf->ignore_headers->nelts = 0; + } + else { + if ((conf->ignore_headers_set == CACHE_IGNORE_HEADERS_UNSET) || + (conf->ignore_headers->nelts)) { + /* Only add header if no "None" has been found in header list + * so far. + * (When 'None' is passed, IGNORE_HEADERS_SET && nelts == 0.) + */ + new = (char **)apr_array_push(conf->ignore_headers); + (*new) = header; + } + } + conf->ignore_headers_set = CACHE_IGNORE_HEADERS_SET; + return NULL; +} + static const char *add_cache_enable(cmd_parms *parms, void *dummy, const char *type, const char *url) @@ -906,6 +941,9 @@ static const command_rec cache_cmds[] = NULL, RSRC_CONF, "Ignore requests from the client for uncached content"), + AP_INIT_ITERATE("CacheIgnoreHeaders", add_ignore_header, NULL, RSRC_CONF, + "A space separated list of headers that should not be " + "stored by the cache"), AP_INIT_TAKE1("CacheLastModifiedFactor", set_cache_factor, NULL, RSRC_CONF, "The factor used to estimate Expires date from " "LastModified date"), diff --git a/modules/experimental/mod_cache.h b/modules/experimental/mod_cache.h index 1135a4de1b..5a4497bb27 100644 --- a/modules/experimental/mod_cache.h +++ b/modules/experimental/mod_cache.h @@ -133,6 +133,12 @@ typedef struct { /** ignore client's requests for uncached responses */ int ignorecachecontrol; int ignorecachecontrol_set; + /** store the headers that should not be stored in the cache */ + apr_array_header_t *ignore_headers; + /* flag if CacheIgnoreHeader has been set */ + #define CACHE_IGNORE_HEADERS_SET 1 + #define CACHE_IGNORE_HEADERS_UNSET 0 + int ignore_headers_set; } cache_server_conf; /* cache info information */ @@ -255,7 +261,9 @@ CACHE_DECLARE(const char *)ap_cache_tokstr(apr_pool_t *p, const char *list, cons /* 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(apr_pool_t *pool, apr_table_t *t); +CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_hdrs_out(apr_pool_t *pool, + apr_table_t *t, + server_rec *s); /** * cache_storage.c diff --git a/modules/experimental/mod_disk_cache.c b/modules/experimental/mod_disk_cache.c index 6ec6fd9e04..dfca6ea1f4 100644 --- a/modules/experimental/mod_disk_cache.c +++ b/modules/experimental/mod_disk_cache.c @@ -606,7 +606,8 @@ static apr_status_t store_headers(cache_handle_t *h, request_rec *r, cache_info if (r->headers_out) { apr_table_t *headers_out; - headers_out = ap_cache_cacheable_hdrs_out(r->pool, r->headers_out); + headers_out = ap_cache_cacheable_hdrs_out(r->pool, r->headers_out, + r->server); if (!apr_table_get(headers_out, "Content-Type") && r->content_type) { @@ -627,7 +628,8 @@ static apr_status_t store_headers(cache_handle_t *h, request_rec *r, cache_info if (r->headers_in) { apr_table_t *headers_in; - headers_in = ap_cache_cacheable_hdrs_out(r->pool, r->headers_in); + headers_in = ap_cache_cacheable_hdrs_out(r->pool, r->headers_in, + r->server); rv = store_table(dobj->hfd, headers_in); if (rv != APR_SUCCESS) { return rv; diff --git a/modules/experimental/mod_mem_cache.c b/modules/experimental/mod_mem_cache.c index f34ba809d7..db7cedd5cd 100644 --- a/modules/experimental/mod_mem_cache.c +++ b/modules/experimental/mod_mem_cache.c @@ -744,13 +744,16 @@ static apr_status_t store_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, - ap_cache_cacheable_hdrs_out(r->pool, r->headers_out)); + ap_cache_cacheable_hdrs_out(r->pool, r->headers_out, + r->server)); if (rc != APR_SUCCESS) { return rc; } rc = serialize_table(&mobj->err_header_out, &mobj->num_err_header_out, - ap_cache_cacheable_hdrs_out(r->pool, r->err_headers_out)); + ap_cache_cacheable_hdrs_out(r->pool, + r->err_headers_out, + r->server)); if (rc != APR_SUCCESS) { return rc; } |