Commit f2caddcf authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Fix a bug in setting *.ttl variables from VCL and go over

testcases at the same time.

Spotted by:	UPLEX
parent 0c6ef776
......@@ -483,17 +483,23 @@ VRT_r_bereq_retries(const struct vrt_ctx *ctx)
}
/*--------------------------------------------------------------------
* NB: TTL is relative to when object was created, whereas grace and
* keep are relative to ttl.
* In exp.*:
* t_origin is absolute
* ttl is relative to t_origin
* grace&keep are relative to ttl
* In VCL:
* ttl is relative to now
* grace&keep are relative to ttl
*/
#define VRT_DO_EXP_L(which, sexp, fld) \
#define VRT_DO_EXP_L(which, sexp, fld, offset) \
\
void \
VRT_l_##which##_##fld(const struct vrt_ctx *ctx, double a) \
{ \
\
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
a += (offset); \
if (a < 0.0) \
a = 0.0; \
sexp.fld = a; \
......@@ -506,23 +512,28 @@ VRT_l_##which##_##fld(const struct vrt_ctx *ctx, double a) \
double \
VRT_r_##which##_##fld(const struct vrt_ctx *ctx) \
{ \
double d; \
\
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
if (sexp.fld > 0.0) \
return(sexp.fld - offset); \
return(0.0); \
d = sexp.fld; \
if (d <= 0.0) \
d = 0.0; \
d -= (offset); \
return(d); \
}
VRT_DO_EXP_R(obj, ctx->req->objcore->exp, ttl,
(ctx->req->t_req - ctx->req->objcore->exp.t_origin))
ctx->now - ctx->req->objcore->exp.t_origin)
VRT_DO_EXP_R(obj, ctx->req->objcore->exp, grace, 0)
VRT_DO_EXP_R(obj, ctx->req->objcore->exp, keep, 0)
VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, ttl)
VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, ttl, 0)
VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, grace)
VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, ttl,
ctx->now - ctx->bo->fetch_objcore->exp.t_origin)
VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, ttl,
ctx->now - ctx->bo->fetch_objcore->exp.t_origin)
VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, grace, 0)
VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, grace, 0)
VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, keep)
VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, keep, 0)
VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, keep, 0)
/*--------------------------------------------------------------------
......
......@@ -11,6 +11,7 @@ server s1 {
txresp -status "304" \
-hdr "Last-Modified: Thu, 26 Jun 2008 12:00:01 GMT" \
-hdr "Snafu: 2" \
-hdr "Grifle: 3" \
-nolen
} -start
......@@ -40,6 +41,7 @@ client c1 {
rxresp
expect resp.bodylen == 13
expect resp.http.foobar == foo0
expect resp.http.grifle == 3
expect resp.http.snafu == 2a
} -run
......@@ -7,6 +7,7 @@ server s1 {
varnish v1 -vcl+backend {
sub vcl_backend_response {
set beresp.http.fooA = beresp.ttl;
set beresp.ttl = 10s;
set beresp.http.fooB = beresp.ttl;
}
......@@ -22,21 +23,22 @@ client c1 {
txreq
rxresp
expect resp.bodylen == 40
expect resp.http.fooA == 19.000
expect resp.http.fooB == 10.000
delay 2
txreq
rxresp
expect resp.bodylen == 40
# XXX: should be: < 8
expect resp.http.fooA == 19.000
expect resp.http.fooB == 10.000
expect resp.http.foo != 10.000
expect resp.http.foo != 9.000
expect resp.http.foo <= 8.000
delay 2
txreq
rxresp
expect resp.bodylen == 40
expect resp.http.fooA == 19.000
expect resp.http.fooB == 10.000
expect resp.http.foo <= 5.000
expect resp.http.foo <= 6.000
} -run
......@@ -21,7 +21,7 @@ client c1 {
txreq
rxresp
expect resp.bodylen == 40
expect resp.http.x-ttl == 23.000
expect resp.http.x-ttl == 19.000
expect resp.http.Age == 4
......@@ -29,13 +29,13 @@ client c1 {
txreq
rxresp
expect resp.bodylen == 40
expect resp.http.x-ttl == 23.000
expect resp.http.x-remaining-ttl ~ ^17\.0|^16\.[89]
expect resp.http.x-ttl == 19.000
expect resp.http.x-remaining-ttl <= 17.000
delay 2
txreq
rxresp
expect resp.bodylen == 40
expect resp.http.x-ttl == 23.000
expect resp.http.x-remaining-ttl ~ ^15\.0|^14\.[89]
expect resp.http.x-ttl == 19.000
expect resp.http.x-remaining-ttl <= 15.000
} -run
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