diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c index f00b37ebb1e..7e8e1872078 100644 --- a/bin/varnishd/cache/cache_rfc2616.c +++ b/bin/varnishd/cache/cache_rfc2616.c @@ -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, diff --git a/bin/varnishtest/tests/b00073.vtc b/bin/varnishtest/tests/b00073.vtc new file mode 100644 index 00000000000..82d59888ffb --- /dev/null +++ b/bin/varnishtest/tests/b00073.vtc @@ -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