[master] 69838a5 add std.getenv()

Nils Goroll nils.goroll at uplex.de
Mon Dec 5 09:59:06 CET 2016


commit 69838a5cc3250b79ad03d264ba49f37f814c6f8f
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 dfedbd7..7caa2c0 100644
--- a/lib/libvmod_std/vmod.vcc
+++ b/lib/libvmod_std/vmod.vcc
@@ -274,6 +274,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 6354d69..609c56c 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -248,3 +248,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