diff --git a/modules/cache/cache_util.c b/modules/cache/cache_util.c index 78770ff..c830aa4 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: %" APR_TIME_T_FMT " <=> %" APR_TIME_T_FMT " (%" APR_TIME_T_FMT ") - %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..c8006c5 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: %" APR_TIME_T_FMT " (%" APR_TIME_T_FMT " + %" APR_TIME_T_FMT ") - %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 */ @@ -434,6 +451,11 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in) if (r->status != HTTP_OK && r->status != HTTP_NON_AUTHORITATIVE && r->status != HTTP_MULTIPLE_CHOICES && r->status != HTTP_MOVED_PERMANENTLY + && r->status != HTTP_MOVED_TEMPORARILY + && r->status != HTTP_FORBIDDEN + && r->status != HTTP_NOT_FOUND + && r->status != HTTP_SERVICE_UNAVAILABLE + && r->status != HTTP_INTERNAL_SERVER_ERROR && r->status != HTTP_NOT_MODIFIED) { /* RFC2616 13.4 we are allowed to cache 200, 203, 206, 300, 301 or 410 * We don't cache 206, because we don't (yet) cache partial responses. @@ -517,7 +539,7 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in) else if (ap_cache_liststr(NULL, apr_table_get(r->headers_out, "Vary"), "*", NULL)) { - reason = "Vary header contains '*'"; + //reason = "Vary header contains '*'"; } else if (r->no_cache) { /* or we've been asked not to cache it above */ @@ -1136,6 +1158,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 +1256,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 */ diff --git a/modules/cache/mod_disk_cache.c b/modules/cache/mod_disk_cache.c index 4148b37..7aa5d11 100644 --- a/modules/cache/mod_disk_cache.c +++ b/modules/cache/mod_disk_cache.c @@ -818,7 +818,8 @@ static apr_status_t store_headers(cache_handle_t *h, request_rec *r, cache_info tmp = apr_table_get(r->headers_out, "Vary"); - if (tmp) { + /* if (tmp) { */ + if (0) { apr_array_header_t* varray; apr_uint32_t format = VARY_FORMAT_VERSION;