Commit 7375e05e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Wean cache_rfc2616.c from struct exp.

parent 6aca2141
...@@ -1050,7 +1050,8 @@ int WS_Overflowed(const struct ws *ws); ...@@ -1050,7 +1050,8 @@ int WS_Overflowed(const struct ws *ws);
void *WS_Printf(struct ws *ws, const char *fmt, ...) __v_printflike(2, 3); void *WS_Printf(struct ws *ws, const char *fmt, ...) __v_printflike(2, 3);
/* cache_rfc2616.c */ /* cache_rfc2616.c */
void RFC2616_Ttl(struct busyobj *, double now); void RFC2616_Ttl(struct busyobj *, double now, double *t_origin,
float *ttl, float *grace, float *keep);
unsigned RFC2616_Req_Gzip(const struct http *); unsigned RFC2616_Req_Gzip(const struct http *);
int RFC2616_Do_Cond(const struct req *sp); int RFC2616_Do_Cond(const struct req *sp);
void RFC2616_Weaken_Etag(struct http *hp); void RFC2616_Weaken_Etag(struct http *hp);
......
...@@ -384,8 +384,12 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo) ...@@ -384,8 +384,12 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
/* /*
* What does RFC2616 think about TTL ? * What does RFC2616 think about TTL ?
*/ */
EXP_Clr(&bo->fetch_objcore->exp); RFC2616_Ttl(bo, now,
RFC2616_Ttl(bo, now); &bo->fetch_objcore->exp.t_origin,
&bo->fetch_objcore->exp.ttl,
&bo->fetch_objcore->exp.grace,
&bo->fetch_objcore->exp.keep
);
/* private objects have negative TTL */ /* private objects have negative TTL */
if (bo->fetch_objcore->flags & OC_F_PRIVATE) if (bo->fetch_objcore->flags & OC_F_PRIVATE)
......
...@@ -62,25 +62,27 @@ ...@@ -62,25 +62,27 @@
*/ */
void void
RFC2616_Ttl(struct busyobj *bo, double now) RFC2616_Ttl(struct busyobj *bo, double now, double *t_origin,
float *ttl, float *grace, float *keep)
{ {
unsigned max_age, age; unsigned max_age, age;
double h_date, h_expires; double h_date, h_expires;
const char *p; const char *p;
const struct http *hp; const struct http *hp;
struct exp *expp;
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
expp = &bo->fetch_objcore->exp;
hp = bo->beresp;
assert(now != 0.0 && !isnan(now)); assert(now != 0.0 && !isnan(now));
expp->t_origin = now; AN(t_origin);
AN(ttl);
AN(grace);
AN(keep);
expp->ttl = cache_param->default_ttl; *t_origin = now;
expp->grace = cache_param->default_grace; *ttl = cache_param->default_ttl;
expp->keep = cache_param->default_keep; *grace = cache_param->default_grace;
*keep = cache_param->default_keep;
hp = bo->beresp;
max_age = age = 0; max_age = age = 0;
h_expires = 0; h_expires = 0;
...@@ -98,7 +100,7 @@ RFC2616_Ttl(struct busyobj *bo, double now) ...@@ -98,7 +100,7 @@ RFC2616_Ttl(struct busyobj *bo, double now)
* compatible with fractional seconds. * compatible with fractional seconds.
*/ */
age = strtoul(p, NULL, 10); age = strtoul(p, NULL, 10);
expp->t_origin -= age; *t_origin -= age;
} }
if (http_GetHdr(hp, H_Expires, &p)) if (http_GetHdr(hp, H_Expires, &p))
...@@ -109,7 +111,7 @@ RFC2616_Ttl(struct busyobj *bo, double now) ...@@ -109,7 +111,7 @@ RFC2616_Ttl(struct busyobj *bo, double now)
switch (http_GetStatus(hp)) { switch (http_GetStatus(hp)) {
default: default:
expp->ttl = -1.; *ttl = -1.;
break; break;
case 302: /* Moved Temporarily */ case 302: /* Moved Temporarily */
case 307: /* Temporary Redirect */ case 307: /* Temporary Redirect */
...@@ -119,7 +121,7 @@ RFC2616_Ttl(struct busyobj *bo, double now) ...@@ -119,7 +121,7 @@ RFC2616_Ttl(struct busyobj *bo, double now)
* Do not apply the default ttl, only set a ttl if Cache-Control * Do not apply the default ttl, only set a ttl if Cache-Control
* or Expires are present. Uncacheable otherwise. * or Expires are present. Uncacheable otherwise.
*/ */
expp->ttl = -1.; *ttl = -1.;
/* FALL-THROUGH */ /* FALL-THROUGH */
case 200: /* OK */ case 200: /* OK */
case 203: /* Non-Authoritative Information */ case 203: /* Non-Authoritative Information */
...@@ -144,7 +146,7 @@ RFC2616_Ttl(struct busyobj *bo, double now) ...@@ -144,7 +146,7 @@ RFC2616_Ttl(struct busyobj *bo, double now)
else else
max_age = strtoul(p, NULL, 0); max_age = strtoul(p, NULL, 0);
expp->ttl = max_age; *ttl = max_age;
break; break;
} }
...@@ -155,7 +157,7 @@ RFC2616_Ttl(struct busyobj *bo, double now) ...@@ -155,7 +157,7 @@ RFC2616_Ttl(struct busyobj *bo, double now)
/* If backend told us it is expired already, don't cache. */ /* If backend told us it is expired already, don't cache. */
if (h_expires < h_date) { if (h_expires < h_date) {
expp->ttl = 0; *ttl = 0;
break; break;
} }
...@@ -167,9 +169,9 @@ RFC2616_Ttl(struct busyobj *bo, double now) ...@@ -167,9 +169,9 @@ RFC2616_Ttl(struct busyobj *bo, double now)
* trust Expires: relative to our own clock. * trust Expires: relative to our own clock.
*/ */
if (h_expires < now) if (h_expires < now)
expp->ttl = 0; *ttl = 0;
else else
expp->ttl = h_expires - now; *ttl = h_expires - now;
break; break;
} else { } else {
/* /*
...@@ -177,7 +179,7 @@ RFC2616_Ttl(struct busyobj *bo, double now) ...@@ -177,7 +179,7 @@ RFC2616_Ttl(struct busyobj *bo, double now)
* derive a relative time from the two headers. * derive a relative time from the two headers.
* (the negative ttl case is caught above) * (the negative ttl case is caught above)
*/ */
expp->ttl = (int)(h_expires - h_date); *ttl = (int)(h_expires - h_date);
} }
} }
...@@ -186,19 +188,19 @@ RFC2616_Ttl(struct busyobj *bo, double now) ...@@ -186,19 +188,19 @@ RFC2616_Ttl(struct busyobj *bo, double now)
* RFC5861 outlines a way to control the use of stale responses. * RFC5861 outlines a way to control the use of stale responses.
* We use this to initialize the grace period. * We use this to initialize the grace period.
*/ */
if (expp->ttl >= 0 && http_GetHdrField(hp, H_Cache_Control, if (*ttl >= 0 && http_GetHdrField(hp, H_Cache_Control,
"stale-while-revalidate", &p) && p != NULL) { "stale-while-revalidate", &p) && p != NULL) {
if (*p == '-') if (*p == '-')
expp->grace = 0; *grace = 0;
else else
expp->grace = strtoul(p, NULL, 0); *grace = strtoul(p, NULL, 0);
} }
VSLb(bo->vsl, SLT_TTL, VSLb(bo->vsl, SLT_TTL,
"RFC %.0f %.0f %.0f %.0f %.0f %.0f %.0f %u", "RFC %.0f %.0f %.0f %.0f %.0f %.0f %.0f %u",
expp->ttl, expp->grace, -1., now, *ttl, *grace, -1., now,
expp->t_origin, h_date, h_expires, max_age); *t_origin, h_date, h_expires, max_age);
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
......
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