Commit f997adb9 authored by Geoff Simmons's avatar Geoff Simmons

Add reader.synth().

parent c2c1aa25
......@@ -67,6 +67,16 @@ cached contents are returned.
XXX ...
.. _xreader.synth():
VOID xreader.synth()
--------------------
Generate a synthetic client response body from the file contents. This
method may only be called in ``vcl_synth``.
XXX ...
.. _file.version():
STRING version()
......
# looks like -*- vcl -*-
varnishtest "reader.synth()"
shell {echo -n "foo bar baz quux" > ${tmpdir}/synth}
varnish v1 -vcl {
import ${vmod_file};
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new rdr = file.reader("${tmpdir}/synth", ttl=0.1s);
}
sub vcl_recv {
return (synth(200));
}
sub vcl_synth {
rdr.synth();
return (deliver);
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.body == "foo bar baz quux"
} -run
shell {echo -n "quux baz bar foo" > ${tmpdir}/synth}
delay .1
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.body == "quux baz bar foo"
} -run
shell {rm -f ${tmpdir}/synth}
delay .1
client c1 {
txreq
expect_close
} -run
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error {^rdr\.synth\(\): vmod file failure: rdr: cannot read info about}
expect * = End
} -run
shell {touch ${tmpdir}/synth}
varnish v1 -vcl {
import ${vmod_file};
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new rdr = file.reader("${tmpdir}/synth");
}
sub vcl_recv {
rdr.synth();
}
}
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 * = End
} -start
client c1 {
txreq
rxresp
expect resp.status == 503
expect resp.reason == "VCL failed"
} -run
logexpect l1 -wait
......@@ -473,6 +473,38 @@ vmod_reader_get(VRT_CTX, struct VPFX(file_reader) *rdr)
return (rdr->addr);
}
VCL_VOID
vmod_reader_synth(VRT_CTX, struct VPFX(file_reader) *rdr)
{
const char *p[0];
struct strands strands = { 1, p };
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->vcl_name);
return;
}
AZ(pthread_rwlock_rdlock(&rdr->lock));
if (rdr->flags & RDR_ERROR) {
AN(strcmp(rdr->errbuf, NO_ERR));
VRT_fail(ctx, "%s.synth(): %s", rdr->vcl_name, rdr->errbuf);
AZ(pthread_rwlock_unlock(&rdr->lock));
return;
}
AN(rdr->flags & RDR_MAPPED);
AN(rdr->addr);
strands.p[0] = rdr->addr;
VRT_synth_page(ctx, &strands);
AZ(pthread_rwlock_unlock(&rdr->lock));
return;
}
VCL_STRING
vmod_version(VRT_CTX)
{
......
......@@ -50,6 +50,13 @@ cached contents are returned.
XXX ...
$Method VOID .synth()
Generate a synthetic client response body from the file contents. This
method may only be called in ``vcl_synth``.
XXX ...
$Function STRING version()
Return the version string for this VMOD.
......
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