Commit c15eefb1 authored by Nils Goroll's avatar Nils Goroll

add return(restart) from vcl_recv

This is already possible with some overhead (for example with a
de-tour via vcl_pass), but I see absolutely no reason why we should
not allow direct restarts from recv.

The use case is to rewrite the request and re-start processing of the
rewritten request as if it was received as such. This is also possible
already with some vcl sub juggling, but is complicated by the VCL call
loop detection. Use of restarts avoids this complication and is safe
due to max_restarts.
parent 756940fe
......@@ -918,6 +918,9 @@ cnt_recv(struct worker *wrk, struct req *req)
case VCL_RET_SYNTH:
req->req_step = R_STP_SYNTH;
break;
case VCL_RET_RESTART:
req->req_step = R_STP_RESTART;
break;
case VCL_RET_FAIL:
req->req_step = R_STP_VCLFAIL;
break;
......
varnishtest "Check that max_restarts works and that we don't fall over"
varnishtest "Check that max_restarts outside vcl_recv works and that we don't fall over"
server s1 {
rxreq
......
varnishtest "Check that max_restarts from vcl_recv works and that we don't fall over"
varnish v1 -vcl {
backend dummy { .host = "${bad_backend}"; }
sub vcl_recv {
return (restart);
}
sub vcl_synth {
# when we end up here, we have _exceeded_ the number
# allowed restarts
if (req.restarts == 3) {
set resp.status = 200;
set resp.reason = "restart=3";
} elsif (req.restarts > 3) {
set resp.status = 501;
set resp.reason = "restart>3";
} elsif (req.restarts < 3) {
set resp.status = 500;
set resp.reason = "restart<3";
}
}
} -start
varnish v1 -cliok "param.set max_restarts 2"
client c1 {
txreq -url "/"
rxresp
expect resp.status == 200
} -run
varnish v1 -cliok "param.set max_restarts 3"
client c1 {
txreq -url "/"
rxresp
expect resp.status == 501
} -run
varnish v1 -cliok "param.set max_restarts 1"
client c1 {
txreq -url "/"
rxresp
expect resp.status == 500
} -run
......@@ -47,6 +47,8 @@ VCL and bundled VMODs
* workspace overflows in ``std.syslog()`` are ignored
* added ``return(restart)`` from ``vcl_recv{}``
Logging / statistics
--------------------
......
......@@ -93,7 +93,7 @@ returns = (
('recv',
"C",
('fail', 'synth', 'pass', 'pipe', 'hash', 'purge', 'vcl')
('fail', 'synth', 'restart', '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