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