[CHERI] 634060677 RFC2616: Function to derive LM header strength
Poul-Henning Kamp
phk at FreeBSD.org
Tue Nov 29 12:48:10 UTC 2022
commit 63406067777f7c737b5c2f51b3f8d224dd1d6e2f
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