[master] ba79652ee RFC2616: Function to derive LM header strength

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Nov 28 15:33:06 UTC 2022


commit ba79652eeec65fdf46c25008fe4abc00df51ee3e
Author: AlveElde <alve_elde at hotmail.com>
Date:   Fri Sep 16 16:38:49 2022 +0200

    RFC2616: Function to derive LM header strength
    
    Per RFC9110, the Last-Modified header is not a strong validator unless
    it is at least one second older than the Date header. This is to prevent
    revalidating content that has been changed within a second of the last
    response. In the case of an intermediate cache like Varnish, a weak
    Last-Modified validator is "weaker" than a weak ETag, and should not be
    used for revalidating content.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 49ef26195..c59564737 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -880,6 +880,8 @@ unsigned RFC2616_Req_Gzip(const struct http *);
 int RFC2616_Do_Cond(const struct req *sp);
 void RFC2616_Weaken_Etag(struct http *hp);
 void RFC2616_Vary_AE(struct http *hp);
+const char * RFC2616_Strong_LM(struct http *hp, struct worker *wrk,
+    struct objcore *oc);
 
 /*
  * We want to cache the most recent timestamp in wrk->lastused to avoid
diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c
index 93bc30843..e45ad12fd 100644
--- a/bin/varnishd/cache/cache_rfc2616.c
+++ b/bin/varnishd/cache/cache_rfc2616.c
@@ -356,3 +356,36 @@ RFC2616_Vary_AE(struct http *hp)
 		http_SetHeader(hp, "Vary: Accept-Encoding");
 	}
 }
+
+/*--------------------------------------------------------------------*/
+
+const char *
+RFC2616_Strong_LM(struct http *hp, struct worker *wrk, struct objcore *oc)
+{
+	const char *p = NULL, *e = NULL;
+	vtim_real lm, d;
+
+	CHECK_OBJ_ORNULL(wrk, WORKER_MAGIC);
+	CHECK_OBJ_ORNULL(oc, OBJCORE_MAGIC);
+	CHECK_OBJ_ORNULL(hp, HTTP_MAGIC);
+
+	if (hp != NULL) {
+		http_GetHdr(hp, H_Last_Modified, &p);
+		http_GetHdr(hp, H_Date, &e);
+	} else if (wrk != NULL && oc != NULL) {
+		p = HTTP_GetHdrPack(wrk, oc, H_Last_Modified);
+		e = HTTP_GetHdrPack(wrk, oc, H_Date);
+	}
+
+	if (p == NULL || e == NULL)
+		return (NULL);
+
+	lm = VTIM_parse(p);
+	d = VTIM_parse(e);
+
+	/* The cache entry includes a Date value which is at least one second
+	 * after the Last-Modified value.
+	 * [RFC9110 8.8.2.2-6.2]
+	 */
+	return ((lm && d && lm + 1 <= d) ? p : NULL);
+}


More information about the varnish-commit mailing list