Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
59b47f86
Commit
59b47f86
authored
Mar 29, 2017
by
Jonathan Huot
Committed by
Pål Hermunn Johansen
Apr 25, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add std.file_exists(path) to check if path exists
Conflicts: lib/libvmod_std/vmod.vcc lib/libvmod_std/vmod_std.c
parent
7fc09f9e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
1 deletion
+45
-1
m00029.vtc
bin/varnishtest/tests/m00029.vtc
+22
-0
vmod.vcc
lib/libvmod_std/vmod.vcc
+10
-0
vmod_std.c
lib/libvmod_std/vmod_std.c
+13
-1
No files found.
bin/varnishtest/tests/m00029.vtc
0 → 100644
View file @
59b47f86
varnishtest "Test std.file_exists"
server s1 {
rxreq
txresp
} -start
varnish v1 -vcl+backend {
import ${vmod_std};
sub vcl_deliver {
set resp.http.existsA = std.file_exists("/non/existent");
set resp.http.existsB = std.file_exists("${tmpdir}/v1/_.vsm");
}
} -start
client c1 {
txreq
rxresp
expect resp.http.existsA == "false"
expect resp.http.existsB == "true"
} -run
lib/libvmod_std/vmod.vcc
View file @
59b47f86
...
...
@@ -104,6 +104,16 @@ Description
Example
set beresp.http.served-by = std.fileread("/etc/hostname");
$Function BOOL file_exists(STRING path)
Description
Returns `true` if path or the file pointed to by path exists,
`false` otherwise.
Example
| if (std.file_exists("/etc/return_503")) {
| return (synth(503, "Varnish is in maintenance"));
| }
$Function VOID collect(HEADER hdr)
Description
...
...
lib/libvmod_std/vmod_std.c
View file @
59b47f86
...
...
@@ -28,14 +28,17 @@
#include "config.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdlib.h>
#include <syslog.h>
#include <unistd.h>
#include "vrt.h"
#include "vtcp.h"
...
...
@@ -176,6 +179,15 @@ vmod_syslog(VRT_CTX, VCL_INT fac, const char *fmt, ...)
va_end
(
ap
);
}
VCL_BOOL
__match_proto__
(
td_std_file_exists
)
vmod_file_exists
(
VRT_CTX
,
VCL_STRING
file_name
)
{
struct
stat
st
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
return
(
stat
(
file_name
,
&
st
)
==
0
);
}
VCL_VOID
__match_proto__
(
td_std_collect
)
vmod_collect
(
VRT_CTX
,
VCL_HEADER
hdr
)
{
...
...
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