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

Enable VCL switching from VCL

parent 2d1c4679
......@@ -688,6 +688,8 @@ cnt_recv(struct worker *wrk, struct req *req)
}
VCL_recv_method(req->vcl, wrk, req, NULL, NULL);
if (wrk->handling == VCL_RET_VCL)
VCL_recv_method(req->vcl, wrk, req, NULL, NULL);
/* Attempts to cache req.body may fail */
if (req->req_body_status == REQ_BODY_FAIL) {
......@@ -714,6 +716,12 @@ cnt_recv(struct worker *wrk, struct req *req)
SHA256_Final(req->digest, &sha256ctx);
switch(recv_handling) {
case VCL_RET_VCL:
VSLb(req->vsl, SLT_VCL_Error,
"return(vcl) only allowed from active (top) VCL.");
req->err_code = 503;
req->req_step = R_STP_SYNTH;
return (REQ_FSM_MORE);
case VCL_RET_PURGE:
req->req_step = R_STP_PURGE;
return (REQ_FSM_MORE);
......
......@@ -453,6 +453,8 @@ VRT_vcl_select(VRT_CTX, VCL_VCL vcl)
CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
VCL_Rel(&req->vcl);
vcl_get(&req->vcl, vcl);
/* XXX: better logging */
VSLb(ctx->req->vsl, SLT_Debug, "Now using %s VCL", vcl->loaded_name);
}
struct vclref *
......
varnishtest "Switching VCL from VCL"
server s1 {
rxreq
txresp
} -start
varnish v1 -vcl+backend {
sub vcl_deliver {
set resp.http.vcl = "vclA";
}
} -start
varnish v1 -clierr 106 "vcl.label vcl.A vcl1"
varnish v1 -cliok "vcl.label vclA vcl1"
varnish v1 -vcl+backend {
sub vcl_recv {
if (req.http.vcl == "vcl1") {
return (vcl(vclA));
}
}
sub vcl_deliver {
set resp.http.vcl = "vcl2";
}
}
varnish v1 -cliok "vcl.label vclB vcl2"
varnish v1 -cliok "vcl.list"
client c1 {
txreq
rxresp
expect resp.http.vcl == vcl2
txreq -hdr "vcl: vcl1"
rxresp
expect resp.http.vcl == vclA
} -run
varnish v1 -clierr 106 "vcl.discard vcl1"
varnish v1 -vcl+backend { sub vcl_recv { return (vcl(vclB)); } }
client c1 {
txreq -hdr "vcl: vcl1"
rxresp
expect resp.status == 503
} -run
delay .2
varnish v1 -vcl+backend { sub vcl_recv { return (vcl(vclA)); } }
varnish v1 -vcl+backend { sub vcl_recv { return (vcl(vclA)); } }
varnish v1 -vcl+backend { sub vcl_recv { return (vcl(vclA)); } }
varnish v1 -vcl+backend { sub vcl_recv { return (vcl(vclA)); } }
varnish v1 -clierr 106 "vcl.discard vclA"
varnish v1 -vcl+backend { }
varnish v1 -cliok "vcl.discard vcl3"
varnish v1 -cliok "vcl.discard vcl4"
varnish v1 -cliok "vcl.discard vcl5"
varnish v1 -cliok "vcl.discard vcl6"
varnish v1 -cliok "vcl.discard vcl7"
varnish v1 -cliok "vcl.discard vclB"
varnish v1 -cliok "vcl.discard vcl2"
varnish v1 -cliok "vcl.discard vclA"
varnish v1 -cliok "vcl.discard vcl1"
......@@ -85,7 +85,7 @@ returns = (
('recv',
"C",
('synth', 'pass', 'pipe', 'hash', 'purge',)
('synth', 'pass', 'pipe', 'hash', 'purge', 'vcl')
),
('pipe',
"C",
......
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