[master] cff50548b Keep Age information on passes
Nils Goroll
nils.goroll at uplex.de
Wed Feb 26 13:08:10 UTC 2020
commit cff50548b9633b676d71fc82c9103b368807e9a3
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Fri Feb 21 16:40:38 2020 +0100
Keep Age information on passes
When doing a pass, we would remove the Age header from the backend, and
create a new one based on the time the fetch was initiated. This creates
problems when calculating the time to live in downstream caches (browser
cache or layered varnishes).
With this patch, the RFC_2616_Ttl calculation routine is run also for
passes, where the t_origin field of the object is adjusted for an incoming
Age header. This makes sure that the Age header generated during delivery
is correct. The rest of the Ttl calculation is skipped for passes,
including the logging of SLT_TTL "RFC".
Fixes: varnishcache/varnish-cache#3221
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 613327c2d..7bc595613 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -415,21 +415,12 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
http_CollectHdr(bo->beresp, H_Cache_Control);
http_CollectHdr(bo->beresp, H_Vary);
- if (bo->fetch_objcore->flags & OC_F_PRIVATE) {
- /* private objects have negative TTL */
- bo->fetch_objcore->t_origin = now;
- bo->fetch_objcore->ttl = -1.;
- bo->fetch_objcore->grace = 0;
- bo->fetch_objcore->keep = 0;
- } else {
- /* What does RFC2616 think about TTL ? */
- RFC2616_Ttl(bo, now,
- &bo->fetch_objcore->t_origin,
- &bo->fetch_objcore->ttl,
- &bo->fetch_objcore->grace,
- &bo->fetch_objcore->keep
- );
- }
+ /* What does RFC2616 think about TTL ? */
+ RFC2616_Ttl(bo, now,
+ &bo->fetch_objcore->t_origin,
+ &bo->fetch_objcore->ttl,
+ &bo->fetch_objcore->grace,
+ &bo->fetch_objcore->keep);
AZ(bo->do_esi);
AZ(bo->was_304);
diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c
index 781a108cc..f00b37ebb 100644
--- a/bin/varnishd/cache/cache_rfc2616.c
+++ b/bin/varnishd/cache/cache_rfc2616.c
@@ -94,6 +94,7 @@ RFC2616_Ttl(struct busyobj *bo, vtim_real now, vtim_real *t_origin,
const struct http *hp;
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+ CHECK_OBJ_NOTNULL(bo->fetch_objcore, OBJCORE_MAGIC);
assert(now != 0.0 && !isnan(now));
AN(t_origin);
AN(ttl);
@@ -121,6 +122,19 @@ RFC2616_Ttl(struct busyobj *bo, vtim_real now, vtim_real *t_origin,
*t_origin -= age;
}
+ if (bo->fetch_objcore->flags & OC_F_PRIVATE) {
+ /* Pass object. Halt the processing here, keeping only the
+ * parsed value of t_origin, as that will be needed to
+ * synthesize a correct Age header in delivery. The
+ * SLT_TTL log tag at the end of this function is
+ * deliberetaly skipped to avoid confusion when reading
+ * the log.*/
+ *ttl = -1;
+ *grace = 0;
+ *keep = 0;
+ return;
+ }
+
if (http_GetHdr(hp, H_Expires, &p))
h_expires = VTIM_parse(p);
diff --git a/bin/varnishtest/tests/r03221.vtc b/bin/varnishtest/tests/r03221.vtc
new file mode 100644
index 000000000..8fab00691
--- /dev/null
+++ b/bin/varnishtest/tests/r03221.vtc
@@ -0,0 +1,27 @@
+varnishtest "Handling of Age when return(pass)"
+
+server s1 {
+ rxreq
+ txresp -hdr "cache-control: max-age=2" -hdr "age: 1"
+
+ rxreq
+ txresp -hdr "cache-control: max-age=2" -hdr "age: 1"
+} -start
+
+varnish v1 -vcl+backend {
+ sub vcl_recv {
+ if (req.url == "/pass") {
+ return(pass);
+ }
+ }
+} -start
+
+client c1 {
+ txreq
+ rxresp
+ expect resp.http.age == 1
+
+ txreq -url /pass
+ rxresp
+ expect resp.http.age == 1
+} -run
More information about the varnish-commit
mailing list