[master] 5d088eb Make it possible to compare STRING_LIST in vcl.

Poul-Henning Kamp phk at FreeBSD.org
Fri Jan 13 10:39:05 CET 2017


commit 5d088ebfad3086403b85daf18d4bf048ad180c9b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Jan 13 09:37:38 2017 +0000

    Make it possible to compare STRING_LIST in vcl.
    
    Fixes #2078

diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc
index cb8ea6e..42f0f8e 100644
--- a/bin/varnishtest/tests/v00020.vtc
+++ b/bin/varnishtest/tests/v00020.vtc
@@ -319,3 +319,22 @@ varnish v1 -errvcl {Comparison of different types: BACKEND '==' STRING} {
 		}
 	}
 }
+
+server s1 {
+	rxreq
+	txresp -hdr "bar: X"
+} -start
+
+varnish v1 -vcl+backend {
+
+	sub vcl_deliver {
+		set resp.http.foo =
+		    (resp.http.foo + resp.http.bar) == ("X" + resp.http.foo);
+	}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.http.foo == "true"
+} -run
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 9581cbf..7e92471 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -1102,6 +1102,8 @@ static const struct cmps {
 
 	{STRING,	T_EQ,	"!VRT_strcmp(\v1, \v2)" },
 	{STRING,	T_NEQ,	"VRT_strcmp(\v1, \v2)" },
+	{STRING_LIST,	T_EQ,	"!VRT_strcmp(\v1, \v2)" },
+	{STRING_LIST,	T_NEQ,	"VRT_strcmp(\v1, \v2)" },
 
 	{VOID, 0, NULL}
 };
@@ -1133,6 +1135,11 @@ vcc_expr_cmp(struct vcc *tl, struct expr **e, vcc_type_t fmt)
 			break;
 	if (cp->fmt != VOID) {
 		vcc_NextToken(tl);
+		if ((*e)->fmt == STRING_LIST) {
+			// XXX: This is not optimal, but we can't pass two
+			// STRING_LIST's to a function anyway...
+			vcc_expr_tostring(tl, e, STRING);
+		}
 		vcc_expr_strfold(tl, &e2, (*e)->fmt);
 		ERRCHK(tl);
 		if (e2->fmt != (*e)->fmt) { /* XXX */



More information about the varnish-commit mailing list