[4.1] 14ce480 Make sure Age is always less than max-age
PÃ¥l Hermunn Johansen
hermunn at varnish-software.com
Thu Apr 6 13:55:05 CEST 2017
commit 14ce48044a680032adc51244f58dac03c391cea1
Author: Reza Naghibi <reza at naghibi.com>
Date: Wed Feb 15 16:16:07 2017 -0500
Make sure Age is always less than max-age
By rounding Age down, we make sure Age < max-age while the object
is fresh. Otherwise, we can prematurely get Age == max-age and Varnish
will calculate that as a 0s TTL and create a pass scenario.
Conflicts:
bin/varnishd/cache/cache_req_fsm.c
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 5214c46..cedfe1e 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -154,7 +154,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
* age. Truncate to zero in that case).
*/
http_PrintfHeader(req->resp, "Age: %.0f",
- fmax(0., req->t_prev - req->objcore->exp.t_origin));
+ floor(fmax(0., req->t_prev - req->objcore->exp.t_origin));
http_SetHeader(req->resp, "Via: 1.1 varnish-v4");
diff --git a/bin/varnishtest/tests/s00006.vtc b/bin/varnishtest/tests/s00006.vtc
new file mode 100644
index 0000000..c347e67
--- /dev/null
+++ b/bin/varnishtest/tests/s00006.vtc
@@ -0,0 +1,30 @@
+varnishtest "Check that Age is always less than max-age while not stale"
+
+server s1 {
+ rxreq
+ expect req.url == "/"
+ txresp -hdr "Cache-control: max-age=2"
+} -start
+
+varnish v1 -vcl+backend { } -start
+
+client c1 {
+ txreq -url "/"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.Age == 0
+
+ delay 0.8
+
+ txreq -url "/"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.Age == 0
+
+ delay 1.0
+
+ txreq -url "/"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.Age == 1
+} -run
More information about the varnish-commit
mailing list