Commit 59aab527 authored by Geoff Simmons's avatar Geoff Simmons

Add reader.size().

parent 38f67414
......@@ -98,6 +98,15 @@ error.
XXX ...
.. _xreader.size():
BYTES xreader.size()
--------------------
Returns the size of the file when it was most recently checked.
XXX ...
.. _file.version():
STRING version()
......
# looks like -*- vcl -*-
varnishtest "methods for information about files and timers"
shell {echo -n "foo bar baz quux" > ${tmpdir}/sz}
varnish v1 -vcl {
import ${vmod_file};
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new rdr = file.reader("${tmpdir}/sz", ttl=0.1s);
}
sub vcl_recv {
set req.http.Size = rdr.size();
return (synth(200));
}
sub vcl_synth {
set resp.http.Size = req.http.Size;
return (deliver);
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
# Oddly, the BYTES to string conversion results in "16.000".
expect resp.http.Size ~ {^16\D}
} -run
shell {echo -n "foo" > ${tmpdir}/sz}
delay .1
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.Size ~ {^3\D}
} -run
shell {rm -f ${tmpdir}/sz}
delay .1
client c1 {
txreq
rxresp
expect resp.status == 503
expect resp.reason == "VCL failed"
} -run
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error {^rdr\.size\(\): vmod file failure: rdr: cannot read info about}
expect * = End
} -run
......@@ -524,6 +524,28 @@ vmod_reader_errmsg(VRT_CTX, struct VPFX(file_reader) *rdr)
return (rdr->errbuf);
}
VCL_BYTES
vmod_reader_size(VRT_CTX, struct VPFX(file_reader) *rdr)
{
VCL_BYTES sz;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(rdr, FILE_READER_MAGIC);
CHECK_OBJ_NOTNULL(rdr->info, FILE_INFO_MAGIC);
AZ(pthread_rwlock_rdlock(&rdr->lock));
if (rdr->flags & RDR_ERROR) {
AN(strcmp(rdr->errbuf, NO_ERR));
VRT_fail(ctx, "%s.size(): %s", rdr->vcl_name, rdr->errbuf);
AZ(pthread_rwlock_unlock(&rdr->lock));
return (0);
}
sz = rdr->info->len - 1;
AZ(pthread_rwlock_unlock(&rdr->lock));
return (sz);
}
VCL_STRING
vmod_version(VRT_CTX)
{
......
......@@ -72,6 +72,12 @@ error.
XXX ...
$Method BYTES .size()
Returns the size of the file when it was most recently checked.
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