[master] d9f7e92 Merge stale-while-revalidate handling into RFC2616_Ttl
Federico G. Schwindt
fgsch at lodoss.net
Mon Oct 27 15:53:24 CET 2014
commit d9f7e92cacb777410f7fd4e8beb1fe3e6c660799
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date: Mon Oct 27 13:43:16 2014 +0000
Merge stale-while-revalidate handling into RFC2616_Ttl
Log the grace period as part of the SLT_TTL VSL tag.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index e88a4af..dd2f71f 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1085,7 +1085,6 @@ 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);
-void RFC5861_Stale(const struct busyobj *);
/* stevedore.c */
int STV_NewObject(struct objcore *, struct worker *,
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index ceaf931..bfbd3c9 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -366,8 +366,6 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
EXP_Clr(&bo->fetch_objcore->exp);
RFC2616_Ttl(bo, now);
- RFC5861_Stale(bo);
-
/* private objects have negative TTL */
if (bo->fetch_objcore->flags & OC_F_PRIVATE)
bo->fetch_objcore->exp.ttl = -1.;
diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c
index 4733b56..89949e4 100644
--- a/bin/varnishd/cache/cache_rfc2616.c
+++ b/bin/varnishd/cache/cache_rfc2616.c
@@ -173,10 +173,22 @@ RFC2616_Ttl(struct busyobj *bo, double now)
}
- /* calculated TTL, Our time, Date, Expires, max-age, age */
+ /*
+ * RFC5861 outlines a way to control the use of stale responses.
+ * We use this to initialize the grace period.
+ */
+ if (expp->ttl >= 0 && http_GetHdrField(hp, H_Cache_Control,
+ "stale-while-revalidate", &p) && p != NULL) {
+
+ if (*p == '-')
+ expp->grace = 0;
+ else
+ expp->grace = strtoul(p, NULL, 0);
+ }
+
VSLb(bo->vsl, SLT_TTL,
"RFC %.0f %.0f %.0f %.0f %.0f %.0f %.0f %u",
- expp->ttl, -1., -1., now,
+ expp->ttl, expp->grace, -1., now,
expp->t_origin, h_date, h_expires, max_age);
}
@@ -275,35 +287,3 @@ RFC2616_Vary_AE(struct http *hp)
http_SetHeader(hp, "Vary: Accept-Encoding");
}
}
-
-/*
- * RFC5861 outlines a way to control the use of stale responses.
- * We use this to initialize the grace period.
- */
-
-void
-RFC5861_Stale(const struct busyobj *bo)
-{
- const char *p;
- const struct http *hp;
- struct exp *expp;
-
- expp = &bo->fetch_objcore->exp;
-
- /*
- * If we are not meant to cache this ignore any potential
- * stale-while-revalidate values.
- */
- if (expp->ttl < 0.)
- return;
-
- hp = bo->beresp;
-
- if (http_GetHdrField(hp, H_Cache_Control,
- "stale-while-revalidate", &p) && p != NULL) {
- if (*p == '-')
- expp->grace = 0;
- else
- expp->grace = strtoul(p, NULL, 0);
- }
-}
diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h
index b483f2c..7dd918d 100644
--- a/include/tbl/vsl_tags.h
+++ b/include/tbl/vsl_tags.h
@@ -211,7 +211,7 @@ SLTM(TTL, 0, "TTL set on object",
"\n"
"The last four fields are only present in \"RFC\" headers.\n\n"
"Examples::\n\n"
- "\tRFC 60 -1 -1 1312966109 1312966109 1312966109 0 60\n"
+ "\tRFC 60 10 -1 1312966109 1312966109 1312966109 0 60\n"
"\tVCL 120 10 0 1312966111\n"
"\n"
)
More information about the varnish-commit
mailing list