Skip to content

Commit

Permalink
Make sure Age is always less than max-age
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rezan authored and hermunn committed Apr 6, 2017
1 parent 09ce321 commit 14ce480
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bin/varnishd/cache/cache_req_fsm.c
Expand Up @@ -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");

Expand Down
30 changes: 30 additions & 0 deletions 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

0 comments on commit 14ce480

Please sign in to comment.