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
edfb6893
Commit
edfb6893
authored
Oct 17, 2024
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the .check() method.
parent
fa595a34
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
1 deletion
+111
-1
README.rst
README.rst
+28
-0
Makefile.am
src/Makefile.am
+2
-1
vmod_file.c
src/vmod_file.c
+12
-0
vmod_file.vcc
src/vmod_file.vcc
+25
-0
check.vtc
src/vtc/check.vtc
+44
-0
No files found.
README.rst
View file @
edfb6893
...
@@ -377,6 +377,34 @@ Example::
...
@@ -377,6 +377,34 @@ Example::
.. _reader.error():
.. _reader.error():
.. _xreader.check():
VOID xreader.check()
--------------------
Run a synchronous check of the file, and update the cached contents if
the file has been changed. This is the same check that runs
periodically in the background after the reader object is created.
Since the file check does not scale well, this method should be used
judiciously as a part of request processing. A reasonable use case is
an administrative request with restricted access, to be called as a
part of an automated process when the underlying file is changed, so
that the changes are reflected promptly.
Example::
if (req.url == "/update-files") {
# Assume that this ACL defines internal admin networks.
# Return error status 403 Forbidden if the client IP doesn't
# match.
if (client.ip !~ admin_network) {
return (synth(403));
}
# Internal admins may run a synchronous file check.
rdr.check();
}
.. _xreader.error():
.. _xreader.error():
BOOL xreader.error()
BOOL xreader.error()
...
...
src/Makefile.am
View file @
edfb6893
...
@@ -33,7 +33,8 @@ TESTS = \
...
@@ -33,7 +33,8 @@ TESTS = \
vtc/info.vtc
\
vtc/info.vtc
\
vtc/path.vtc
\
vtc/path.vtc
\
vtc/synth.vtc
\
vtc/synth.vtc
\
vtc/temperature.vtc
vtc/temperature.vtc
\
vtc/check.vtc
# Documentation
# Documentation
...
...
src/vmod_file.c
View file @
edfb6893
...
@@ -650,6 +650,18 @@ vmod_reader_blob(VRT_CTX, struct VPFX(file_reader) *rdr)
...
@@ -650,6 +650,18 @@ vmod_reader_blob(VRT_CTX, struct VPFX(file_reader) *rdr)
return
(
blob
);
return
(
blob
);
}
}
VCL_VOID
vmod_reader_check
(
VRT_CTX
,
struct
VPFX
(
file_reader
)
*
rdr
)
{
union
sigval
val
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
rdr
,
FILE_READER_MAGIC
);
val
.
sival_ptr
=
rdr
;
check
(
val
);
}
VCL_BOOL
VCL_BOOL
vmod_reader_error
(
VRT_CTX
,
struct
VPFX
(
file_reader
)
*
rdr
)
vmod_reader_error
(
VRT_CTX
,
struct
VPFX
(
file_reader
)
*
rdr
)
{
{
...
...
src/vmod_file.vcc
View file @
edfb6893
...
@@ -354,6 +354,31 @@ Example::
...
@@ -354,6 +354,31 @@ Example::
.. _reader.error():
.. _reader.error():
$Method VOID .check()
Run a synchronous check of the file, and update the cached contents if
the file has been changed. This is the same check that runs
periodically in the background after the reader object is created.
Since the file check does not scale well, this method should be used
judiciously as a part of request processing. A reasonable use case is
an administrative request with restricted access, to be called as a
part of an automated process when the underlying file is changed, so
that the changes are reflected promptly.
Example::
if (req.url == "/update-files") {
# Assume that this ACL defines internal admin networks.
# Return error status 403 Forbidden if the client IP doesn't
# match.
if (client.ip !~ admin_network) {
return (synth(403));
}
# Internal admins may run a synchronous file check.
rdr.check();
}
$Method BOOL .error()
$Method BOOL .error()
Return true if and only if an error condition was determined the last
Return true if and only if an error condition was determined the last
...
...
src/vtc/check.vtc
0 → 100644
View file @
edfb6893
# looks like -*- vcl -*-
varnishtest ".check() method"
shell {echo -n "foo bar baz quux" > ${tmpdir}/file}
varnish v1 -vcl {
import file;
backend b None;
sub vcl_init {
# Set a long TTL so that the background check
# doesn't run during the test.
new rdr = file.reader("${tmpdir}/file", ttl=1y);
}
sub vcl_recv {
if (req.url == "/check") {
rdr.check();
}
return (synth(200));
}
sub vcl_synth {
set resp.http.Get = rdr.get();
return (deliver);
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.Get == "foo bar baz quux"
} -run
shell {echo -n "quux baz bar foo" > ${tmpdir}/file}
client c1 {
txreq -url "/check"
rxresp
expect resp.status == 200
expect resp.http.Get == "quux baz bar foo"
} -run
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