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

Nils Goroll nils.goroll at uplex.de
Mon Aug 25 13:03:11 CEST 2014


commit 4e9fb4b339b7df0679609d699aa7f5c31aa32595
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 cddab7c..0f9292a 100644
--- a/bin/varnishd/cache/cache_rfc2616.c
+++ b/bin/varnishd/cache/cache_rfc2616.c
@@ -136,10 +136,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