[Remove entries to the current 2.0 section below, when backported]
+ *) Modified the cache code to be header-location agnostic. Also
+ fixed a number of other cache code bugs related to PR 15852.
+ Includes a patch submitted by Sushma Rai <rsushma@novell.com>.
+ This fixes mod_mem_cache but not mod_disk_cache yet so I'm not
+ closing the PR since that is what they are using. [Paul J. Reder]
+
*) Switch to APR 1.0 API.
*) Modify ap_get_client_block() to note if it has seen EOS.
switch ((rv = cache_run_open_entity(h, r, type, key))) {
case OK: {
char *vary = NULL;
+ char *varyhdr = NULL;
if (cache_read_entity_headers(h, r) != APR_SUCCESS) {
/* TODO: Handle this error */
return DECLINED;
*
* RFC2616 13.6 and 14.44 describe the Vary mechanism.
*/
- vary = apr_pstrdup(r->pool, apr_table_get(r->headers_out, "Vary"));
+ if ((varyhdr = apr_table_get(r->err_headers_out, "Vary")) == NULL) {
+ varyhdr = apr_table_get(r->headers_out, "Vary");
+ }
+ vary = apr_pstrdup(r->pool, varyhdr);
while (vary && *vary) {
char *name = vary;
const char *h1, *h2;
apr_time_t now)
{
apr_time_t apparent_age, corrected_received_age, response_delay,
- corrected_initial_age, resident_time, current_age;
+ corrected_initial_age, resident_time, current_age,
+ age_value_usec;
+
+ age_value_usec = apr_time_from_sec(age_value);
/* Perform an HTTP/1.1 age calculation. (RFC2616 13.2.3) */
apparent_age = MAX(0, info->response_time - info->date);
- corrected_received_age = MAX(apparent_age, age_value);
+ corrected_received_age = MAX(apparent_age, age_value_usec);
response_delay = info->response_time - info->request_time;
corrected_initial_age = corrected_received_age + response_delay;
resident_time = now - info->response_time;
int age_in_errhdr = 0;
const char *cc_cresp, *cc_ceresp, *cc_req;
const char *agestr = NULL;
+ const char *expstr = NULL;
char *val;
apr_time_t age_c = 0;
cache_info *info = &(cache->handle->cache_obj->info);
age_in_errhdr = 1;
}
+ if (!(expstr = apr_table_get(r->err_headers_out, "Expires"))) {
+ expstr = apr_table_get(r->headers_out, "Expires");
+ }
+
/* calculate age of object */
age = ap_cache_current_age(info, age_c, r->request_time);
"proxy-revalidate", NULL)))) {
maxstale = 0;
}
+
/* handle expiration */
if (((smaxage != -1) && (age < (smaxage - minfresh))) ||
((maxage != -1) && (age < (maxage + maxstale - minfresh))) ||
((smaxage == -1) && (maxage == -1) &&
(info->expire != APR_DATE_BAD) &&
(age < (apr_time_sec(info->expire - info->date) + maxstale - minfresh)))) {
+ const char *warn_head;
+ apr_table_t *head_ptr;
+
+ warn_head = apr_table_get(r->headers_out, "Warning");
+ if (warn_head != NULL) {
+ head_ptr = r->headers_out;
+ }
+ else {
+ warn_head = apr_table_get(r->err_headers_out, "Warning");
+ head_ptr = r->err_headers_out;
+ }
+
/* it's fresh darlings... */
/* set age header on response */
if (age_in_errhdr) {
(info->expire != APR_DATE_BAD &&
(info->expire - info->date) > age))) {
/* make sure we don't stomp on a previous warning */
- apr_table_merge(r->headers_out, "Warning", "110 Response is stale");
+ if ((warn_head == NULL) ||
+ ((warn_head != NULL) && (ap_strstr_c(warn_head, "110") == NULL))) {
+ apr_table_merge(head_ptr, "Warning", "110 Response is stale");
+ }
+ }
+ /*
+ * If none of Expires, Cache-Control: max-age, or Cache-Control:
+ * s-maxage appears in the response, and the respose header age
+ * calculated is more than 24 hours add the warning 113
+ */
+ if ((maxage_cresp == -1) && (smaxage == -1) &&
+ (expstr == NULL) && (age > 86400)) {
+
+ /* Make sure we don't stomp on a previous warning, and don't dup
+ * a 113 marning that is already present. Also, make sure to add
+ * the new warning to the correct *headers_out location.
+ */
+ if ((warn_head == NULL) ||
+ ((warn_head != NULL) && (ap_strstr_c(warn_head, "113") == NULL))) {
+ apr_table_merge(head_ptr, "Warning", "113 Heuristic expiration");
+ }
}
return 1; /* Cache object is fresh (enough) */
}
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.
+/* Create a new table consisting of those elements from an input
+ * headers table that are allowed to be stored in a cache.
*/
-CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_hdrs_out(request_rec *r)
+CACHE_DECLARE(apr_table_t *)ap_cache_cacheable_hdrs_out(apr_pool_t *pool,
+ apr_table_t *t)
{
- /* Make a copy of the response headers, and remove from
+ /* 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
*/
apr_table_t *headers_out;
- headers_out = apr_table_copy(r->pool, r->headers_out);
+ headers_out = apr_table_copy(pool, t);
apr_table_unset(headers_out, "Connection");
apr_table_unset(headers_out, "Keep-Alive");
apr_table_unset(headers_out, "Proxy-Authenticate");
return OK;
}
else {
- r->err_headers_out = apr_table_make(r->pool, 3);
+ if (!r->err_headers_out) {
+ r->err_headers_out = apr_table_make(r->pool, 3);
+ }
/* stale data available */
if (lookup) {
return DECLINED;
}
/* else if non-conditional request */
else {
+ /* Temporarily hack this to work the way it had been. Its broken,
+ * but its broken the way it was before. I'm working on figuring
+ * out why the filter add in the conditional filter doesn't work. pjr
+ *
+ * info = &(cache->handle->cache_obj->info);
+ *
+ * Uncomment the above when the code in cache_conditional_filter_handle
+ * is properly fixed... pjr
+ */
+
/* fudge response into a conditional */
if (info && info->etag) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0,
static int cache_in_filter(ap_filter_t *f, apr_bucket_brigade *in)
{
int rv;
+ int date_in_errhdr = 0;
request_rec *r = f->r;
cache_request_rec *cache;
cache_server_conf *conf;
/* read expiry date; if a bad date, then leave it so the client can
* read it
*/
- exps = apr_table_get(r->headers_out, "Expires");
+ 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;
}
/* read the last-modified date; if the date is bad, then delete it */
- lastmods = apr_table_get(r->headers_out, "Last-Modified");
+ lastmods = apr_table_get(r->err_headers_out, "Last-Modified");
+ if (lastmods ==NULL) {
+ lastmods = apr_table_get(r->headers_out, "Last-Modified");
+ }
if (lastmods != NULL) {
if (APR_DATE_BAD == (lastmod = apr_date_parse_http(lastmods))) {
lastmods = NULL;
conf = (cache_server_conf *) ap_get_module_config(r->server->module_config, &cache_module);
/* read the etag and cache-control from the entity */
- etag = apr_table_get(r->headers_out, "Etag");
- cc_out = apr_table_get(r->headers_out, "Cache-Control");
+ etag = apr_table_get(r->err_headers_out, "Etag");
+ if (etag == NULL) {
+ etag = apr_table_get(r->headers_out, "Etag");
+ }
+ cc_out = apr_table_get(r->err_headers_out, "Cache-Control");
+ if (cc_out == NULL) {
+ cc_out = apr_table_get(r->headers_out, "Cache-Control");
+ }
/*
* what responses should we not cache?
/* Set the content length if known.
*/
- cl = apr_table_get(r->headers_out, "Content-Length");
+ cl = apr_table_get(r->err_headers_out, "Content-Length");
+ if (cl == NULL) {
+ cl = apr_table_get(r->headers_out, "Content-Length");
+ }
if (cl) {
size = apr_atoi64(cl);
}
}
/* pre-existing cache handle and 304, make entity fresh */
else if (r->status == HTTP_NOT_MODIFIED) {
- /* update headers */
+ /* update headers: TODO */
/* remove this filter ??? */
*/
/* Read the date. Generate one if one is not supplied */
- dates = apr_table_get(r->headers_out, "Date");
+ dates = apr_table_get(r->err_headers_out, "Date");
+ if (dates != NULL) {
+ date_in_errhdr = 1;
+ }
+ else {
+ dates = apr_table_get(r->headers_out, "Date");
+ }
if (dates != NULL) {
info->date = apr_date_parse_http(dates);
}
now = apr_time_now();
if (info->date == APR_DATE_BAD) { /* No, or bad date */
char *dates;
- /* no date header! */
+ /* no date header (or bad header)! */
/* add one; N.B. use the time _now_ rather than when we were checking
* the cache
*/
+ if (date_in_errhdr == 1) {
+ apr_table_unset(r->err_headers_out, "Date");
+ }
date = now;
dates = apr_pcalloc(r->pool, MAX_STRING_LEN);
apr_rfc822_date(dates, now);
/* if no expiry date then
* if lastmod
- * expiry date = now + min((date - lastmod) * factor, maxexpire)
+ * expiry date = date + min((date - lastmod) * factor, maxexpire)
* else
- * expire date = now + defaultexpire
+ * expire date = date + defaultexpire
*/
if (exp == APR_DATE_BAD) {
/* if lastmod == date then you get 0*conf->factor which results in
*/
if ((lastmod != APR_DATE_BAD) && (lastmod < date)) {
apr_time_t x = (apr_time_t) ((date - lastmod) * conf->factor);
+
if (x > conf->maxex) {
x = conf->maxex;
}
- exp = now + x;
+ exp = date + x;
}
else {
- exp = now + conf->defex;
+ exp = date + conf->defex;
}
}
info->expire = exp;
info->content_type = apr_pstrdup(r->pool, r->content_type);
+ info->etag = apr_pstrdup(r->pool, etag);
+ info->lastmod = apr_pstrdup(r->pool, lastmods);
info->filename = apr_pstrdup(r->pool, r->filename );
/*
/* 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_DECLARE(apr_table_t *)ap_cache_cacheable_hdrs_out(apr_pool_t *pool, apr_table_t *t);
/**
* cache_storage.c
if (r->headers_out) {
int i;
- apr_table_t* headers_out = ap_cache_cacheable_hdrs_out(r);
+ apr_table_t* headers_out = ap_cache_cacheable_hdrs_out(r->pool, r->headers_out);
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) {
typedef struct mem_cache_object {
cache_type_e type;
apr_ssize_t num_header_out;
+ apr_ssize_t num_err_header_out;
apr_ssize_t num_subprocess_env;
apr_ssize_t num_notes;
apr_ssize_t num_req_hdrs;
cache_header_tbl_t *header_out;
+ cache_header_tbl_t *err_header_out;
cache_header_tbl_t *subprocess_env;
cache_header_tbl_t *notes;
cache_header_tbl_t *req_hdrs; /* for Vary negotiation */
free(mobj->header_out[0].hdr);
free(mobj->header_out);
}
+ if (mobj->err_header_out) {
+ if (mobj->err_header_out[0].hdr)
+ free(mobj->err_header_out[0].hdr);
+ free(mobj->err_header_out);
+ }
if (mobj->subprocess_env) {
if (mobj->subprocess_env[0].hdr)
free(mobj->subprocess_env[0].hdr);
h->req_hdrs = apr_table_make(r->pool, mobj->num_req_hdrs);
r->headers_out = apr_table_make(r->pool, mobj->num_header_out);
+ r->err_headers_out = apr_table_make(r->pool, mobj->num_err_header_out);
r->subprocess_env = apr_table_make(r->pool, mobj->num_subprocess_env);
r->notes = apr_table_make(r->pool, mobj->num_notes);
rc = unserialize_table( mobj->header_out,
mobj->num_header_out,
r->headers_out);
+ rc = unserialize_table( mobj->err_header_out,
+ mobj->num_err_header_out,
+ r->err_headers_out);
rc = unserialize_table( mobj->subprocess_env,
mobj->num_subprocess_env,
r->subprocess_env);
/* 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));
+ ap_cache_cacheable_hdrs_out(r->pool, r->headers_out));
+ 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));
if (rc != APR_SUCCESS) {
return rc;
}
}
memcpy(obj->info.content_type, info->content_type, len);
}
+ if (info->etag) {
+ apr_size_t len = strlen(info->etag) + 1;
+ obj->info.etag = (char*) malloc(len);
+ if (!obj->info.etag) {
+ return APR_ENOMEM;
+ }
+ memcpy(obj->info.etag, info->etag, len);
+ }
+ if (info->lastmods) {
+ apr_size_t len = strlen(info->lastmods) + 1;
+ obj->info.lastmods = (char*) malloc(len);
+ if (!obj->info.lastmods) {
+ return APR_ENOMEM;
+ }
+ memcpy(obj->info.lastmods, info->lastmods, len);
+ }
if ( info->filename) {
apr_size_t len = strlen(info->filename) + 1;
obj->info.filename = (char*) malloc(len);