From: Paul J. Reder Date: Mon, 29 Sep 2003 21:09:47 +0000 (+0000) Subject: *) cache_util: Fix ap_check_cache_feshness to check max_age, smax_age, and X-Git-Tag: 2.0.48~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5092ea222a0085a7eb8adbc312be276674066fa4;p=thirdparty%2Fapache%2Fhttpd.git *) cache_util: Fix ap_check_cache_feshness to check max_age, smax_age, and expires as directed in RFC 2616. [Thomas Castelle tcastelle@generali.fr] Reviewed by: Paul J. Reder, Bill Stoddard, and Roy T. Fielding, git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/APACHE_2_0_BRANCH@101351 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 5d8a7678cb8..9513712b6bc 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,8 @@ Changes with Apache 2.0.48 + *) cache_util: Fix ap_check_cache_feshness to check max_age, smax_age, and + expires as directed in RFC 2616. [Thomas Castelle tcastelle@generali.fr] + *) Ensure that ssl-std.conf is generated at configure time, and switch to using the expanded config variables to work the same as httpd-std.conf PR: 1961 diff --git a/STATUS b/STATUS index a88ae1467c9..db42873e972 100644 --- a/STATUS +++ b/STATUS @@ -1,5 +1,5 @@ APACHE 2.0 STATUS: -*-text-*- -Last modified at [$Date: 2003/09/29 12:08:06 $] +Last modified at [$Date: 2003/09/29 21:09:46 $] Release: @@ -78,11 +78,6 @@ PATCHES TO PORT FROM 2.1 http://cvs.apache.org/viewcvs.cgi/httpd-2.0/modules/experimental/mod_mem_cache.c.diff?r1=1.93&r2=1.94 +1: rederpj, fielding, trawick - * Correct the code in ap_check_cache_feshness to check max_age, smax_age, - and expires correctly. This is a RFC 2616 compliance issue. - http://cvs.apache.org/viewcvs.cgi/httpd-2.0/modules/experimental/cache_util.c.diff?r1=1.26&r2=1.27 - +1: rederpj, stoddard, fielding - * mod_rewrite.c: Fix mod_rewrite's support of the [P] option to send rewritten request using "proxy:". The code was adding multiple "proxy:" fields in the rewritten URI. PR: 13946. diff --git a/modules/experimental/cache_util.c b/modules/experimental/cache_util.c index 047d7311d4a..066c02658b2 100644 --- a/modules/experimental/cache_util.c +++ b/modules/experimental/cache_util.c @@ -162,7 +162,8 @@ CACHE_DECLARE(int) ap_cache_check_freshness(cache_request_rec *cache, request_rec *r) { apr_int64_t age, maxage_req, maxage_cresp, maxage, smaxage, maxstale, minfresh; - const char *cc_cresp, *cc_req, *pragma_cresp; + int age_in_errhdr = 0; + const char *cc_cresp, *cc_ceresp, *cc_req; const char *agestr = NULL; char *val; apr_time_t age_c = 0; @@ -201,12 +202,16 @@ CACHE_DECLARE(int) ap_cache_check_freshness(cache_request_rec *cache, * */ cc_cresp = apr_table_get(r->headers_out, "Cache-Control"); + cc_ceresp = apr_table_get(r->err_headers_out, "Cache-Control"); cc_req = apr_table_get(r->headers_in, "Cache-Control"); - /* TODO: pragma_cresp not being used? */ - pragma_cresp = apr_table_get(r->headers_out, "Pragma"); + if ((agestr = apr_table_get(r->headers_out, "Age"))) { age_c = apr_atoi64(agestr); } + else if ((agestr = apr_table_get(r->err_headers_out, "Age"))) { + age_c = apr_atoi64(agestr); + age_in_errhdr = 1; + } /* calculate age of object */ age = ap_cache_current_age(info, age_c, r->request_time); @@ -214,6 +219,9 @@ CACHE_DECLARE(int) ap_cache_check_freshness(cache_request_rec *cache, /* extract s-maxage */ if (cc_cresp && ap_cache_liststr(r->pool, cc_cresp, "s-maxage", &val)) smaxage = apr_atoi64(val); + else if (cc_ceresp && ap_cache_liststr(r->pool, cc_ceresp, "s-maxage", &val)) { + smaxage = apr_atoi64(val); + } else smaxage = -1; @@ -226,6 +234,9 @@ CACHE_DECLARE(int) ap_cache_check_freshness(cache_request_rec *cache, /* extract max-age from response */ if (cc_cresp && ap_cache_liststr(r->pool, cc_cresp, "max-age", &val)) maxage_cresp = apr_atoi64(val); + else if (cc_ceresp && ap_cache_liststr(r->pool, cc_ceresp, "max-age", &val)) { + maxage_cresp = apr_atoi64(val); + } else maxage_cresp = -1; @@ -253,29 +264,44 @@ CACHE_DECLARE(int) ap_cache_check_freshness(cache_request_rec *cache, /* override maxstale if must-revalidate or proxy-revalidate */ if (maxstale && ((cc_cresp && - ap_cache_liststr(NULL, - cc_cresp, "must-revalidate", NULL)) - || (cc_cresp && ap_cache_liststr(NULL, - cc_cresp, - "proxy-revalidate", NULL)))) + ap_cache_liststr(NULL, cc_cresp, + "must-revalidate", NULL)) || + (cc_cresp && + ap_cache_liststr(NULL, cc_cresp, + "proxy-revalidate", NULL)) || + (cc_ceresp && + ap_cache_liststr(NULL, cc_ceresp, + "must-revalidate", NULL)) || + (cc_ceresp && + ap_cache_liststr(NULL, cc_ceresp, + "proxy-revalidate", NULL)))) { maxstale = 0; + } /* handle expiration */ - if ((-1 < smaxage && age < (smaxage - minfresh)) || - (-1 < maxage && age < (maxage + maxstale - minfresh)) || - (info->expire != APR_DATE_BAD && age < (apr_time_sec(info->expire - info->date) + maxstale - minfresh))) { + 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)))) { /* it's fresh darlings... */ /* set age header on response */ - apr_table_set(r->headers_out, "Age", - apr_psprintf(r->pool, "%lu", (unsigned long)age)); + if (age_in_errhdr) { + apr_table_set(r->err_headers_out, "Age", + apr_psprintf(r->pool, "%lu", (unsigned long)age)); + } + else { + apr_table_set(r->headers_out, "Age", + apr_psprintf(r->pool, "%lu", (unsigned long)age)); + } /* add warning if maxstale overrode freshness calculation */ - if (!((-1 < smaxage && age < smaxage) || - (-1 < maxage && age < maxage) || + if (!(((smaxage != -1) && age < smaxage) || + ((maxage != -1) && age < maxage) || (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"); } - return 1; /* Cache object is fresh */ + return 1; /* Cache object is fresh (enough) */ } return 0; /* Cache object is stale */ }