[4.0] e6d50a6 Set default ttl (according to rfc2616 rules) to max-age, do not use Age twice

Lasse Karstensen lkarsten at varnish-software.com
Mon Sep 22 16:38:23 CEST 2014


commit e6d50a6b980bfbffce14df81a0093136bd61e55d
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Aug 25 12:53:49 2014 +0200

    Set default ttl (according to rfc2616 rules) to max-age, do not use Age twice
    
    With 160927b690dd076702601b7407eb71bd423c62dd t_origin got corrected
    by Age, so we already took the age the object had at fetch time into
    consideration for all other calculations.
    
    Fixes #1578

diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c
index 66dbc9b..b0ebaf3 100644
--- a/bin/varnishd/cache/cache_rfc2616.c
+++ b/bin/varnishd/cache/cache_rfc2616.c
@@ -135,10 +135,7 @@ RFC2616_Ttl(struct busyobj *bo, double now)
 			else
 				max_age = strtoul(p, NULL, 0);
 
-			if (age > max_age)
-				expp->ttl = 0;
-			else
-				expp->ttl = max_age - age;
+			expp->ttl = max_age;
 			break;
 		}
 
diff --git a/bin/varnishtest/tests/r01578.vtc b/bin/varnishtest/tests/r01578.vtc
new file mode 100644
index 0000000..3086b6b
--- /dev/null
+++ b/bin/varnishtest/tests/r01578.vtc
@@ -0,0 +1,41 @@
+varnishtest "max-age and age"
+
+server s1 {
+	rxreq
+	txresp -hdr "Cache-Control: max-age=23" -hdr "Age: 4" -bodylen 40
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_backend_response {
+	    	set beresp.http.x-ttl = beresp.ttl;
+	}
+	sub vcl_hit {
+		set req.http.x-remaining-ttl = obj.ttl;
+	}
+	sub vcl_deliver {
+		set resp.http.x-remaining-ttl = req.http.x-remaining-ttl;
+	}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.bodylen == 40
+	expect resp.http.x-ttl == 23.000
+	expect resp.http.Age == 4
+
+
+	delay 2
+	txreq
+	rxresp
+	expect resp.bodylen == 40
+	expect resp.http.x-ttl == 23.000
+	expect resp.http.x-remaining-ttl ~ ^17\.0|^16\.9
+
+	delay 2
+	txreq
+	rxresp
+	expect resp.bodylen == 40
+	expect resp.http.x-ttl == 23.000
+	expect resp.http.x-remaining-ttl ~ ^15\.0|^14\.9
+} -run



More information about the varnish-commit mailing list