Skip to content

Commit

Permalink
Implementing the Cache-Control "must-revalidate" directive
Browse files Browse the repository at this point in the history
  • Loading branch information
ThijsFeryn committed Jul 16, 2020
1 parent 6f7af3a commit a34ec5c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bin/varnishd/cache/cache_rfc2616.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,17 @@ RFC2616_Ttl(struct busyobj *bo, vtim_real now, vtim_real *t_origin,
*grace = rfc2616_time(p);
}

/*
* The "must-revalidate" directive prohibits
* the cache from serving stale data,
* according to RFC7234, 5.2.2.1.
* This sets the grace to zero.
*/
if (*ttl >= 0 && http_GetHdrField(hp, H_Cache_Control,
"must-revalidate", &p)) {
*grace = 0;
}

VSLb(bo->vsl, SLT_TTL,
"RFC %.0f %.0f %.0f %.0f %.0f %.0f %.0f %u %s",
*ttl, *grace, *keep, now,
Expand Down
31 changes: 31 additions & 0 deletions bin/varnishtest/tests/b00073.vtc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
varnishtest "Test must-revalidate"

server s1 {
rxreq
txresp -hdr "Cache-Control: max-age=30"
rxreq
txresp -hdr "Cache-Control: max-age=30, must-revalidate"
rxreq
txresp -hdr "Cache-Control: max-age=30, must-revalidate, stale-while-revalidate=100"
} -start

varnish v1 -vcl+backend {
sub vcl_backend_response {
set beresp.http.grace = beresp.grace;
set beresp.http.ttl = beresp.ttl;
}
} -start

client c1 {
txreq -url /1
rxresp
expect resp.http.grace == 10.000

txreq -url /2
rxresp
expect resp.http.grace == 0.000

txreq -url /3
rxresp
expect resp.http.grace == 0.000
} -run

0 comments on commit a34ec5c

Please sign in to comment.