You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by re...@apache.org on 2003/06/27 23:21:02 UTC
cvs commit: httpd-2.0/modules/experimental cache_util.c
rederpj 2003/06/27 14:21:02
Modified: . CHANGES
modules/experimental cache_util.c
Log:
Correct the code in ap_check_cache_feshness to check max_age, smax_age,
and expires correctly.
Submitted by: Thomas Castelle <tc...@generali.fr>
Reviewed and altered by: Paul J. Reder
Revision Changes Path
1.1204 +4 -0 httpd-2.0/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/httpd-2.0/CHANGES,v
retrieving revision 1.1203
retrieving revision 1.1204
diff -u -r1.1203 -r1.1204
--- CHANGES 25 Jun 2003 20:22:14 -0000 1.1203
+++ CHANGES 27 Jun 2003 21:21:01 -0000 1.1204
@@ -2,6 +2,10 @@
[Remove entries to the current 2.0 section below, when backported]
+ *) Correct the code in ap_check_cache_feshness to check max_age,
+ smax_age, and expires correctly. Patch submitted by Thomas
+ Castelle [Paul J. Reder]
+
*) mod_cgid: Restart the cgid daemon if it crashes. PR 19849
[Glenn Nielsen <gl...@apache.org>]
1.27 +41 -18 httpd-2.0/modules/experimental/cache_util.c
Index: cache_util.c
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/experimental/cache_util.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- cache_util.c 17 Feb 2003 03:12:03 -0000 1.26
+++ cache_util.c 27 Jun 2003 21:21:02 -0000 1.27
@@ -145,7 +145,8 @@
{
apr_int64_t age, maxage_req, maxage_cresp, maxage, smaxage, maxstale;
apr_int64_t 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;
@@ -184,12 +185,16 @@
*
*/
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);
@@ -198,6 +203,9 @@
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;
}
@@ -214,6 +222,9 @@
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;
@@ -250,33 +261,45 @@
/* 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 */
}