I have revisited https://www.varnish-cache.org/trac/ticket/1027 and IIUC phk has now done all the necessary groundwork to allow return(synth) in deliver:
cnt_synth returns with either REQ_FSM_MORE for VCL_RET_RESTART or REQ_FSM_DONE after having called its custom delivery code path via V1D_Deliver_Synth(req). The rest of the calling code in cnt_deliver is identical for restart and synth. If you need historical background: Kristian had left helpful commit links and a summary in https://www.varnish-cache.org/trac/ticket/1027
>From 16a57b3363efd5dcdfa6d1d437bcc5c03ef1069c Mon Sep 17 00:00:00 2001 From: Nils Goroll <[email protected]> Date: Thu, 10 Jul 2014 16:43:28 +0200 Subject: [PATCH] allow return(synth(...)) in vcl_deliver This is possible now because synth responses do not go through deliver any more, as error responses used to. This concludes the fix for #1027 - the actual work was the rewrite of the delivery process. --- bin/varnishd/cache/cache_req_fsm.c | 15 ++++++++-- bin/varnishtest/tests/c00068.vtc | 60 ++++++++++++++++++++++++++++++++++++++ bin/varnishtest/tests/r01027.vtc | 9 ------ lib/libvcc/generate.py | 2 +- 4 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 bin/varnishtest/tests/c00068.vtc delete mode 100644 bin/varnishtest/tests/r01027.vtc diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c index 161c5e8..ccb5036 100644 --- a/bin/varnishd/cache/cache_req_fsm.c +++ b/bin/varnishd/cache/cache_req_fsm.c @@ -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); } diff --git a/bin/varnishtest/tests/c00068.vtc b/bin/varnishtest/tests/c00068.vtc new file mode 100644 index 0000000..817ec32 --- /dev/null +++ b/bin/varnishtest/tests/c00068.vtc @@ -0,0 +1,60 @@ +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 diff --git a/bin/varnishtest/tests/r01027.vtc b/bin/varnishtest/tests/r01027.vtc deleted file mode 100644 index 716e6f0..0000000 --- a/bin/varnishtest/tests/r01027.vtc +++ /dev/null @@ -1,9 +0,0 @@ -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")); - } -} - diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py index a1fd2d7..2906588 100755 --- a/lib/libvcc/generate.py +++ b/lib/libvcc/generate.py @@ -112,7 +112,7 @@ returns =( ), ('deliver', "C", - ('restart', 'deliver',) + ('synth', 'restart', 'deliver',) ), ('synth', "C", -- 2.0.0
_______________________________________________ varnish-dev mailing list [email protected] https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev
