[4.1] 5030448 add std.getenv()
PÃ¥l Hermunn Johansen
hermunn at varnish-software.com
Thu Mar 30 16:42:06 CEST 2017
commit 503044881785d367854018d4a9f15339d6912d50
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Fri Dec 2 10:48:12 2016 +0100
add std.getenv()
Merges #2152
diff --git a/bin/varnishtest/tests/m00026.vtc b/bin/varnishtest/tests/m00026.vtc
new file mode 100644
index 0000000..17ca1ed
--- /dev/null
+++ b/bin/varnishtest/tests/m00026.vtc
@@ -0,0 +1,21 @@
+varnishtest "Test std.getenv"
+
+varnish v1 -vcl {
+ import std;
+
+ backend dummy { .host = "${bad_ip}"; .port = "9080"; }
+
+ sub vcl_recv {
+ return(synth(200));
+ }
+
+ sub vcl_synth {
+ set resp.http.X-PATH = std.getenv("PATH");
+ }
+} -start
+
+client c1 {
+ txreq
+ rxresp
+ expect resp.http.X-PATH ~ "^/"
+} -run
diff --git a/lib/libvmod_std/vmod.vcc b/lib/libvmod_std/vmod.vcc
index bb69945..97d3b5e 100644
--- a/lib/libvmod_std/vmod.vcc
+++ b/lib/libvmod_std/vmod.vcc
@@ -269,6 +269,14 @@ Example
| ...
| }
+$Function STRING getenv(STRING name)
+
+Description
+ Return environment variable *name* or the empty string.
+
+ See getenv(3)
+Example
+ | set req.http.My-Env = getenv("MY_ENV");
SEE ALSO
========
diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c
index 6cd5b8a..685a348 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -253,3 +253,12 @@ vmod_strstr(VRT_CTX, VCL_STRING s1, VCL_STRING s2)
return (NULL);
return (strstr(s1, s2));
}
+
+VCL_STRING __match_proto__(td_std_getenv)
+vmod_getenv(VRT_CTX, VCL_STRING name)
+{
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ if (name == NULL || *name == '\0')
+ return (NULL);
+ return (getenv(name));
+}
More information about the varnish-commit
mailing list