[4.0] efc0340 add std.strstr
Lasse Karstensen
lkarsten at varnish-software.com
Mon Sep 22 16:38:26 CEST 2014
commit efc034099cbe1e34a092089dd58a8cb1e12f6b8b
Author: Per Buer <perbu at varnish-software.com>
Date: Sat Sep 20 17:57:18 2014 +0200
add std.strstr
Conflicts:
lib/libvmod_std/vmod_std.c
diff --git a/bin/varnishtest/tests/m00018.vtc b/bin/varnishtest/tests/m00018.vtc
new file mode 100644
index 0000000..b51ed18
--- /dev/null
+++ b/bin/varnishtest/tests/m00018.vtc
@@ -0,0 +1,34 @@
+varnishtest "Test substring matching in std"
+
+server s1 {
+ rxreq
+ txresp
+
+ rxreq
+ txresp
+} -start
+
+varnish v1 -vcl+backend {
+ import ${vmod_std};
+
+ sub vcl_deliver {
+ if (std.strstr(req.url, "foo")) {
+ set resp.http.sub = "found";
+ } else {
+ set resp.http.sub = "not found";
+ }
+
+ }
+} -start
+
+client c1 {
+ txreq -url "/foobar"
+ rxresp
+ expect resp.http.sub == "found"
+
+
+ txreq -url "/quux"
+ rxresp
+ expect resp.http.sub == "not found"
+} -run
+
diff --git a/lib/libvmod_std/vmod.vcc b/lib/libvmod_std/vmod.vcc
index 5bcc403..01d9274 100644
--- a/lib/libvmod_std/vmod.vcc
+++ b/lib/libvmod_std/vmod.vcc
@@ -195,11 +195,21 @@ $Function STRING querysort(STRING)
Description
Sorts the querystring for cache normalization purposes.
-
Example
set req.url = std.querysort(req.url);
+$Function STRING strstr(STRING, STRING)
+
+Description
+ Returns true if the second string is a substring of the first
+ string. Note that the comparison is case sensitive. You can
+ use the tolower function on both strings if you want case
+ insensitivity.
+Example
+ if (std.strstr(req.url, req.http.x-restrict))
+
+
SEE ALSO
========
diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c
index 1aaec4c..e08229f 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -230,3 +230,14 @@ vmod_timestamp(const struct vrt_ctx *ctx, VCL_STRING label)
VSLb_ts_req(ctx->req, label, VTIM_real());
}
}
+
+
+VCL_STRING __match_proto__(td_std_strstr)
+vmod_strstr(const struct vrt_ctx *ctx, VCL_STRING mstr, VCL_STRING msubstr)
+{
+
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ char *match = strstr(mstr, msubstr);
+
+ return(match);
+}
More information about the varnish-commit
mailing list