diff --git a/modules/cache/cache_util.c b/modules/cache/cache_util.c index 78770ff..5cbd8da 100644 --- a/modules/cache/cache_util.c +++ b/modules/cache/cache_util.c @@ -180,6 +180,14 @@ CACHE_DECLARE(int) ap_cache_check_freshness(cache_handle_t *h, (cache_server_conf *)ap_get_module_config(r->server->module_config, &cache_module); + if (conf->override_expire_set) { + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, + "expire time vs. request time: %ld <=> %ld (%ld) - %s", + info->expire / MSEC_ONE_SEC, + r->request_time/ MSEC_ONE_SEC, + (info->expire - r->request_time) / MSEC_ONE_SEC, r->unparsed_uri); + return info->expire > r->request_time; + } /* * We now want to check if our cached data is still fresh. This depends * on a few things, in this order: diff --git a/modules/cache/mod_cache.c b/modules/cache/mod_cache.c index 27df70d..a8d81d8 100644 --- a/modules/cache/mod_cache.c +++ b/modules/cache/mod_cache.c @@ -18,6 +18,9 @@ #include "mod_cache.h" +// Added by agentzh: +#define DONT_CARE_EXPIRE_STRING "DONTCARE" + module AP_MODULE_DECLARE_DATA cache_module; APR_OPTIONAL_FN_TYPE(ap_cache_generate_key) *cache_generate_key; @@ -385,17 +388,31 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in) /* read expiry date; if a bad date, then leave it so the client can * read it */ - exps = apr_table_get(r->err_headers_out, "Expires"); - if (exps == NULL) { - exps = apr_table_get(r->headers_out, "Expires"); - } - if (exps != NULL) { - if (APR_DATE_BAD == (exp = apr_date_parse_http(exps))) { - exps = NULL; + + // Added by agentzh: + if (conf->override_expire_set) { + // Added by agentzh: + exps = DONT_CARE_EXPIRE_STRING; + exp = r->request_time + conf->override_expire; + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, + "expire overridden: %ld (%ld + %ld) - %s", + exp / MSEC_ONE_SEC, + r->request_time / MSEC_ONE_SEC, + conf->override_expire / MSEC_ONE_SEC, + r->unparsed_uri); + } else { + exps = apr_table_get(r->err_headers_out, "Expires"); + if (exps == NULL) { + exps = apr_table_get(r->headers_out, "Expires"); + } + if (exps != NULL) { + if (APR_DATE_BAD == (exp = apr_date_parse_http(exps))) { + exps = NULL; + } + } + else { + exp = APR_DATE_BAD; } - } - else { - exp = APR_DATE_BAD; } /* read the last-modified date; if the date is bad, then delete it */ @@ -1136,6 +1153,19 @@ static const char *set_cache_defex(cmd_parms *parms, void *dummy, return NULL; } +// Added by agentzh: +static const char *set_cache_override_expire(cmd_parms *parms, void *dummy, + const char *arg) +{ + cache_server_conf *conf; + + conf = + (cache_server_conf *)ap_get_module_config(parms->server->module_config, + &cache_module); + conf->override_expire = (apr_time_t) (atol(arg) * MSEC_ONE_SEC); + conf->override_expire_set = 1; + return NULL; +} static const char *set_cache_factor(cmd_parms *parms, void *dummy, const char *arg) { @@ -1221,6 +1251,10 @@ static const command_rec cache_cmds[] = AP_INIT_TAKE1("CacheLastModifiedFactor", set_cache_factor, NULL, RSRC_CONF, "The factor used to estimate Expires date from " "LastModified date"), + // Added by agentzh: + AP_INIT_TAKE1("CacheOverrideExpire", set_cache_override_expire, NULL, RSRC_CONF, + "The expiration time overridding the one specified by the documents (if any)"), + {NULL} }; diff --git a/modules/cache/mod_cache.h b/modules/cache/mod_cache.h index 4fe8dfc..e102207 100644 --- a/modules/cache/mod_cache.h +++ b/modules/cache/mod_cache.h @@ -153,6 +153,9 @@ typedef struct { /** ignore query-string when caching */ int ignorequerystring; int ignorequerystring_set; + // Added by agentzh: + apr_time_t override_expire; + int override_expire_set; } cache_server_conf; /* cache info information */