Mailing List Archive

[6.0] bdbe85cf5 Keep Age information on passes
commit bdbe85cf50b960a6bb4b362e78a251f15c36ffe6
Author: Martin Blix Grydeland <martin@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 3ce30ca8a..2395b1b33 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -336,21 +336,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 2a1b476dd..8b94ec302 100644
--- a/bin/varnishd/cache/cache_rfc2616.c
+++ b/bin/varnishd/cache/cache_rfc2616.c
@@ -92,6 +92,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);
@@ -119,6 +120,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
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit