[master] 99a9c56 Pass the rx timestamp into RFC2616_Ttl() to collect all the time-math one place.

Poul-Henning Kamp phk at varnish-cache.org
Thu Oct 3 11:51:01 CEST 2013


commit 99a9c56455a8df4364e2757a3eb1e6786bc91423
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Oct 3 09:50:32 2013 +0000

    Pass the rx timestamp into RFC2616_Ttl() to collect all the
    time-math one place.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 36283bd..4b7b90d 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1195,7 +1195,7 @@ void *WS_Copy(struct ws *ws, const void *str, int len);
 char *WS_Snapshot(struct ws *ws);
 
 /* rfc2616.c */
-void RFC2616_Ttl(struct busyobj *);
+void RFC2616_Ttl(struct busyobj *, double now);
 enum body_status RFC2616_Body(struct busyobj *, struct dstat *);
 unsigned RFC2616_Req_Gzip(const struct http *);
 int RFC2616_Do_Cond(const struct req *sp);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 10f1626..5aca605 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -206,8 +206,7 @@ vbf_stp_fetchhdr(struct worker *wrk, struct busyobj *bo)
 	 * What does RFC2616 think about TTL ?
 	 */
 	EXP_Clr(&bo->exp);
-	bo->exp.entered = W_TIM_real(wrk);
-	RFC2616_Ttl(bo);
+	RFC2616_Ttl(bo, W_TIM_real(wrk));
 
 	/* private objects have negative TTL */
 	if (bo->fetch_objcore->flags & OC_F_PRIVATE)
diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c
index 5b887a2..32887a2 100644
--- a/bin/varnishd/cache/cache_rfc2616.c
+++ b/bin/varnishd/cache/cache_rfc2616.c
@@ -63,7 +63,7 @@
  */
 
 void
-RFC2616_Ttl(struct busyobj *bo)
+RFC2616_Ttl(struct busyobj *bo, double now)
 {
 	unsigned max_age, age;
 	double h_date, h_expires;
@@ -76,7 +76,9 @@ RFC2616_Ttl(struct busyobj *bo)
 
 	hp = bo->beresp;
 
-	assert(expp->entered != 0.0 && !isnan(expp->entered));
+	assert(now != 0.0 && !isnan(now));
+	expp->entered = now;
+
 	/* If all else fails, cache using default ttl */
 	expp->ttl = cache_param->default_ttl;
 
@@ -93,6 +95,7 @@ RFC2616_Ttl(struct busyobj *bo)
 		age = strtoul(p, NULL, 0);
 		expp->age = age;
 	}
+
 	if (http_GetHdr(hp, H_Expires, &p))
 		h_expires = VTIM_parse(p);
 
@@ -144,17 +147,16 @@ RFC2616_Ttl(struct busyobj *bo)
 		}
 
 		if (h_date == 0 ||
-		    fabs(h_date - expp->entered) < cache_param->clock_skew) {
+		    fabs(h_date - now) < cache_param->clock_skew) {
 			/*
 			 * If we have no Date: header or if it is
 			 * sufficiently close to our clock we will
 			 * trust Expires: relative to our own clock.
 			 */
-			if (h_expires < expp->entered)
+			if (h_expires < now)
 				expp->ttl = 0;
 			else
-				expp->ttl = h_expires -
-				    expp->entered;
+				expp->ttl = h_expires - now;
 			break;
 		} else {
 			/*
@@ -170,7 +172,7 @@ RFC2616_Ttl(struct busyobj *bo)
 	/* calculated TTL, Our time, Date, Expires, max-age, age */
 	VSLb(bo->vsl, SLT_TTL,
 	    "RFC %.0f %.0f %.0f %.0f %.0f %.0f %.0f %u",
-	    expp->ttl, -1., -1., expp->entered,
+	    expp->ttl, -1., -1., now,
 	    expp->age, h_date, h_expires, max_age);
 }
 



More information about the varnish-commit mailing list