Commit 3fe14e6c authored by Geoff Simmons's avatar Geoff Simmons

.synth() may also be called in vcl_backend_error.

parent 4dffb765
......@@ -312,10 +312,11 @@ message.
VOID xreader.synth()
--------------------
Generate a synthetic client response body from the file contents. This
method may only be called in ``vcl_synth``. Invokes VCL failure if the
most recent update check encountered an error, or if invoked in any
other VCL subroutine besides ``vcl_synth``.
Generate a synthetic response body from the file contents. This method
may only be called in ``vcl_synth`` or ``vcl_backend_error``. Invokes
VCL failure if the most recent update check encountered an error, or
if invoked in any other VCL subroutine besides the two that are
permitted.
Example::
......@@ -323,6 +324,10 @@ Example::
synth_body.synth();
}
sub vcl_backend_error {
synth_body.synth();
}
.. _xreader.blob():
BLOB xreader.blob()
......
......@@ -2,22 +2,34 @@
varnishtest "reader.synth()"
shell {echo -n "foo bar baz quux" > ${tmpdir}/synth}
shell {
echo -n "foo bar baz quux" > ${tmpdir}/synth
echo -n "ouch" > ${tmpdir}/backend_error
}
varnish v1 -vcl {
import ${vmod_file};
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new rdr = file.reader("${tmpdir}/synth", ttl=0.1s);
new synth = file.reader("${tmpdir}/synth", ttl=0.1s);
new backend_err = file.reader("${tmpdir}/backend_error");
}
sub vcl_recv {
if (req.url == "/backend") {
return (pass);
}
return (synth(200));
}
sub vcl_synth {
rdr.synth();
synth.synth();
return (deliver);
}
sub vcl_backend_error {
backend_err.synth();
return (deliver);
}
} -start
......@@ -39,6 +51,13 @@ client c1 {
expect resp.body == "quux baz bar foo"
} -run
client c1 {
txreq -url /backend
rxresp
expect resp.status == 503
expect resp.body == "ouch"
} -run
shell {chmod a-r ${tmpdir}/synth}
delay .1
......@@ -49,7 +68,7 @@ client c1 {
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error {^rdr\.synth\(\): vmod file failure: vcl1\.rdr: cannot open}
expect * = VCL_Error {^synth\.synth\(\): vmod file failure: vcl1\.synth: cannot open}
expect * = End
} -run
......@@ -73,7 +92,7 @@ varnish v1 -vcl {
logexpect l1 -v v1 -d 0 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error {^rdr\.synth\(\) may only be called in vcl_synth$}
expect * = VCL_Error {^rdr\.synth\(\) may only be called in vcl_synth or vcl_backend_error$}
expect * = End
} -start
......
......@@ -531,9 +531,9 @@ vmod_reader_synth(VRT_CTX, struct VPFX(file_reader) *rdr)
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(rdr, FILE_READER_MAGIC);
if ((ctx->method & VCL_MET_SYNTH) == 0) {
VRT_fail(ctx, "%s.synth() may only be called in vcl_synth",
rdr->obj_name);
if ((ctx->method & (VCL_MET_SYNTH | VCL_MET_BACKEND_ERROR)) == 0) {
VRT_fail(ctx, "%s.synth() may only be called in vcl_synth or "
"vcl_backend_error", rdr->obj_name);
return;
}
......
......@@ -292,10 +292,11 @@ message.
$Method VOID .synth()
Generate a synthetic client response body from the file contents. This
method may only be called in ``vcl_synth``. Invokes VCL failure if the
most recent update check encountered an error, or if invoked in any
other VCL subroutine besides ``vcl_synth``.
Generate a synthetic response body from the file contents. This method
may only be called in ``vcl_synth`` or ``vcl_backend_error``. Invokes
VCL failure if the most recent update check encountered an error, or
if invoked in any other VCL subroutine besides the two that are
permitted.
Example::
......@@ -303,6 +304,10 @@ Example::
synth_body.synth();
}
sub vcl_backend_error {
synth_body.synth();
}
$Method BLOB .blob()
Return the file's contents as a BLOB. Invokes VCL failure if the most
......
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