Commit 92004db2 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp Committed by Lasse Karstensen

Make it possible to return synth from vcl_deliver{}

This is now possible because synth responses do not go through
deliver any more, as error responses used to.

Patch by:	Nils Goroll

Much appreciated
parent 3ffbaed8
......@@ -137,11 +137,22 @@ cnt_deliver(struct worker *wrk, struct req *req)
if (req->restarts >= cache_param->max_restarts)
wrk->handling = VCL_RET_DELIVER;
if (wrk->handling == VCL_RET_RESTART) {
if (wrk->handling != VCL_RET_DELIVER) {
(void)HSH_DerefObj(&wrk->stats, &req->obj);
AZ(req->obj);
http_Teardown(req->resp);
req->req_step = R_STP_RESTART;
switch (wrk->handling) {
case VCL_RET_RESTART:
req->req_step = R_STP_RESTART;
break;
case VCL_RET_SYNTH:
req->req_step = R_STP_SYNTH;
break;
default:
INCOMPL();
}
return (REQ_FSM_MORE);
}
......
varnishtest "synth in deliver"
server s1 {
rxreq
txresp -status 200
rxreq
txresp -status 200
rxreq
txresp -status 200
} -start
varnish v1 -vcl+backend {
sub vcl_deliver {
if (req.url == "/332") {
return (synth(332, "FOO"));
} else if (req.url == "/333") {
return (synth(333, "FOO"));
} else {
return (synth(334, "BAR"));
}
}
sub vcl_synth {
if (resp.status == 333) {
set resp.http.connection = "close";
} else if (resp.status == 332) {
if (req.restarts == 0) {
return (restart);
} else {
set resp.http.restarts = req.restarts;
synthetic(req.restarts);
}
}
return (deliver);
}
} -start
client c1 {
txreq -url /334
rxresp
expect resp.status == 334
# cache hit
txreq -url /334
rxresp
expect resp.status == 334
txreq -url /333
rxresp
expect resp.status == 333
expect_close
} -run
client c2 {
txreq -url /332
rxresp
expect resp.status == 332
expect resp.http.restarts == 1
expect resp.bodylen == 1
} -run
varnishtest "Test if you can error in vcl_deliver"
varnish v1 -errvcl {Invalid return "synth"} {
backend b { .host = "127.0.0.1"; }
sub vcl_deliver {
return (synth(201,"ok"));
}
}
......@@ -112,7 +112,7 @@ returns =(
),
('deliver',
"C",
('restart', 'deliver',)
('synth', 'restart', 'deliver',)
),
('synth',
"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