[master] ab2595062 fetch: A weak LM header does not make an IMS candidate
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Mon Nov 28 15:33:07 UTC 2022
commit ab25950629232b56e29251f7a9872ccb4a3f2266
Author: AlveElde <alve_elde at hotmail.com>
Date: Fri Sep 16 16:48:50 2022 +0200
fetch: A weak LM header does not make an IMS candidate
Avoid marking an object as an IMS candidate when a weak Last-Modified
header is the only validator. In the case where there is an ETag AND a
weak Last-Modified header, add a If-None-Match header, but do not add
an If-Modified-Since header.
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index cf1005aa4..2875d2f91 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -274,7 +274,7 @@ vbf_stp_mkbereq(struct worker *wrk, struct busyobj *bo)
ObjCheckFlag(bo->wrk, bo->stale_oc, OF_IMSCAND) &&
(bo->stale_oc->boc != NULL || ObjGetLen(wrk, bo->stale_oc) != 0)) {
AZ(bo->stale_oc->flags & (OC_F_HFM|OC_F_PRIVATE));
- q = HTTP_GetHdrPack(bo->wrk, bo->stale_oc, H_Last_Modified);
+ q = RFC2616_Strong_LM(NULL, wrk, bo->stale_oc);
if (q != NULL)
http_PrintfHeader(bo->bereq0,
"If-Modified-Since: %s", q);
@@ -700,7 +700,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
if (!(oc->flags & OC_F_HFM) &&
http_IsStatus(bo->beresp, 200) && (
- http_GetHdr(bo->beresp, H_Last_Modified, NULL) ||
+ RFC2616_Strong_LM(bo->beresp, NULL, NULL) != NULL ||
http_GetHdr(bo->beresp, H_ETag, NULL)))
ObjSetFlag(bo->wrk, oc, OF_IMSCAND, 1);
diff --git a/bin/varnishtest/tests/b00079.vtc b/bin/varnishtest/tests/b00079.vtc
new file mode 100644
index 000000000..efb451261
--- /dev/null
+++ b/bin/varnishtest/tests/b00079.vtc
@@ -0,0 +1,83 @@
+varnishtest "Test backend IMS with weak and strong LM"
+
+server s1 {
+ rxreq
+ txresp -hdr "Last-Modified: Wed, 11 Sep 2013 13:36:55 GMT" -nodate -body "1"
+
+ # When origin does not send a Date, varnish inserts one, prompting IMS
+ rxreq
+ expect req.http.if-modified-since == "Wed, 11 Sep 2013 13:36:55 GMT"
+ txresp -status 304 -hdr "Last-Modified: Wed, 11 Sep 2013 13:36:55 GMT" \
+ -hdr "Date: Wed, 11 Sep 2013 13:36:55 GMT" \
+
+ # LM was the same as Date
+ rxreq
+ expect req.http.if-modified-since == <undef>
+ txresp -hdr "Last-Modified: Wed, 11 Sep 2013 13:36:55 GMT" \
+ -hdr "Date: Wed, 11 Sep 2013 13:36:56 GMT" \
+ -body "2"
+
+ # LM was one second older than Date
+ rxreq
+ expect req.http.if-modified-since == "Wed, 11 Sep 2013 13:36:55 GMT"
+ txresp -status 304 -hdr "Last-Modified: Wed, 11 Sep 2013 13:36:55 GMT" \
+ -hdr "Date: Wed, 11 Sep 2013 13:36:55 GMT" \
+ -hdr {ETag: "foo"}
+
+ # LM was the same as Date, but we had an ETag, prompting INM
+ rxreq
+ expect req.http.if-modified-since == <undef>
+ expect req.http.if-none-match == {"foo"}
+ txresp -status 304 -hdr "Last-Modified: Wed, 11 Sep 2013 13:36:55 GMT" \
+ -hdr "Date: Wed, 11 Sep 2013 13:36:55 GMT" \
+ -hdr {ETag: "foo"}
+} -start
+
+varnish v1 -vcl+backend {
+ sub vcl_backend_response {
+ set beresp.ttl = 1ms;
+ set beresp.grace = 0s;
+ set beresp.keep = 1m;
+ set beresp.http.was-304 = beresp.was_304;
+ }
+} -start
+
+client c1 {
+ txreq
+ rxresp
+ expect resp.status == 200
+ expect resp.body == "1"
+ expect resp.http.was-304 == "false"
+
+ delay 0.1
+
+ txreq
+ rxresp
+ expect resp.status == 200
+ expect resp.body == "1"
+ expect resp.http.was-304 == "true"
+
+ delay 0.1
+
+ txreq
+ rxresp
+ expect resp.status == 200
+ expect resp.body == "2"
+ expect resp.http.was-304 == "false"
+
+ delay 0.1
+
+ txreq
+ rxresp
+ expect resp.status == 200
+ expect resp.body == "2"
+ expect resp.http.was-304 == "true"
+
+ delay 0.1
+
+ txreq
+ rxresp
+ expect resp.status == 200
+ expect resp.body == "2"
+ expect resp.http.was-304 == "true"
+} -run
More information about the varnish-commit
mailing list