Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-file
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-file
Commits
59aab527
Commit
59aab527
authored
Sep 22, 2019
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add reader.size().
parent
38f67414
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
95 additions
and
0 deletions
+95
-0
README.rst
README.rst
+9
-0
info.vtc
src/tests/info.vtc
+58
-0
vmod_file.c
src/vmod_file.c
+22
-0
vmod_file.vcc
src/vmod_file.vcc
+6
-0
No files found.
README.rst
View file @
59aab527
...
...
@@ -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()
...
...
src/tests/info.vtc
0 → 100644
View file @
59aab527
# 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
src/vmod_file.c
View file @
59aab527
...
...
@@ -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
)
{
...
...
src/vmod_file.vcc
View file @
59aab527
...
...
@@ -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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment