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
46dc6d53
Commit
46dc6d53
authored
Sep 22, 2019
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an example for the reader constructor, and docs for .get().
parent
54d08bfe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
22 deletions
+80
-22
README.rst
README.rst
+40
-11
vmod_file.vcc
src/vmod_file.vcc
+40
-11
No files found.
README.rst
View file @
46dc6d53
...
...
@@ -213,18 +213,47 @@ Regardless of the value of ``log_checks``, errors encountered during
update checks are logged with the tag ``Error``, also with XID 0 (and
hence visible in raw grouping).
Examples::
sub vcl_init {
# A reader for the file at the absolute path, using default
# ttl=120s.
new foo = file.reader("/path/to/foo");
# A reader for the file on the default search path, with
# update checks every five minutes.
new synth_body = file.reader("synth_body.html", ttl=300s);
# A reader for the file on the given search path, with
# default TTL, and logging for update checks.
new bar = file.reader("bar", path="/var/run/d1:/var/run/d2",
log_checks=true);
# A reader for the file with no update checks.
new baz = file.reader("baz", ttl=0s);
}
.. _xreader.get():
STRING xreader.get()
--------------------
Retrieves the contents of file specified in the constructor. If the
``ttl`` has elapsed, then ``.get()`` checks if the file has changed;
if so, the new contents of the file are read, cached and returned. If
the ``ttl`` has not elapsed, or if the file is unchanged, then the
cached contents are returned.
Return the contents of the file specified in the constructor, as
currently cached. If the most recent update check encountered an
error, then VCL failure is invoked (see `ERRORS`_).
XXX ...
Example::
sub vcl_deliver {
set resp.http.Foo = foo.get();
}
Take care if you use ``.get()`` to set a header, as in the example,
that the file contents do *not* end in a newline. If so, then the
newline appears after the header contents, resulting in an empty line
after the header. Since an empty line separates the headers from the
body in an HTTP message, this is very likely to result in an invalid
message.
.. _xreader.synth():
...
...
@@ -241,7 +270,7 @@ XXX ...
BOOL xreader.error()
--------------------
Return
s
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
time the file was checked.
XXX ...
...
...
@@ -251,7 +280,7 @@ XXX ...
STRING xreader.errmsg()
-----------------------
Return
s
the error message for any error condition determined the last
Return the error message for any error condition determined the last
time the file was checked, or a message indicating that there was no
error.
...
...
@@ -262,7 +291,7 @@ XXX ...
BYTES xreader.size()
--------------------
Return
s
the size of the file when it was most recently checked.
Return the size of the file when it was most recently checked.
XXX ...
...
...
@@ -271,7 +300,7 @@ XXX ...
TIME xreader.mtime()
--------------------
Return
s
the modification time of the file determined when it was mostly
Return the modification time of the file determined when it was mostly
recently checked.
XXX ...
...
...
@@ -281,7 +310,7 @@ XXX ...
DURATION xreader.next_check()
-----------------------------
Return
s
the time remaining until the next check will be performed.
Return the time remaining until the next check will be performed.
XXX ...
...
...
src/vmod_file.vcc
View file @
46dc6d53
...
...
@@ -199,15 +199,44 @@ Regardless of the value of ``log_checks``, errors encountered during
update checks are logged with the tag ``Error``, also with XID 0 (and
hence visible in raw grouping).
Examples::
sub vcl_init {
# A reader for the file at the absolute path, using default
# ttl=120s.
new foo = file.reader("/path/to/foo");
# A reader for the file on the default search path, with
# update checks every five minutes.
new synth_body = file.reader("synth_body.html", ttl=300s);
# A reader for the file on the given search path, with
# default TTL, and logging for update checks.
new bar = file.reader("bar", path="/var/run/d1:/var/run/d2",
log_checks=true);
# A reader for the file with no update checks.
new baz = file.reader("baz", ttl=0s);
}
$Method STRING .get()
Retrieves the contents of file specified in the constructor. If the
``ttl`` has elapsed, then ``.get()`` checks if the file has changed;
if so, the new contents of the file are read, cached and returned. If
the ``ttl`` has not elapsed, or if the file is unchanged, then the
cached contents are returned.
Return the contents of the file specified in the constructor, as
currently cached. If the most recent update check encountered an
error, then VCL failure is invoked (see `ERRORS`_).
XXX ...
Example::
sub vcl_deliver {
set resp.http.Foo = foo.get();
}
Take care if you use ``.get()`` to set a header, as in the example,
that the file contents do *not* end in a newline. If so, then the
newline appears after the header contents, resulting in an empty line
after the header. Since an empty line separates the headers from the
body in an HTTP message, this is very likely to result in an invalid
message.
$Method VOID .synth()
...
...
@@ -218,14 +247,14 @@ XXX ...
$Method BOOL .error()
Return
s
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
time the file was checked.
XXX ...
$Method STRING .errmsg()
Return
s
the error message for any error condition determined the last
Return the error message for any error condition determined the last
time the file was checked, or a message indicating that there was no
error.
...
...
@@ -233,20 +262,20 @@ XXX ...
$Method BYTES .size()
Return
s
the size of the file when it was most recently checked.
Return the size of the file when it was most recently checked.
XXX ...
$Method TIME .mtime()
Return
s
the modification time of the file determined when it was mostly
Return the modification time of the file determined when it was mostly
recently checked.
XXX ...
$Method DURATION .next_check()
Return
s
the time remaining until the next check will be performed.
Return the time remaining until the next check will be performed.
XXX ...
...
...
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