Commit 63406067 authored by AlveElde's avatar AlveElde Committed by Poul-Henning Kamp

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.
parent 8fb35335
......@@ -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
......
......@@ -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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment