[master] 968d11d Add ability to use regexp's for expect in HTTP.

Poul-Henning Kamp phk at varnish-cache.org
Thu Oct 11 13:02:24 CEST 2012


commit 968d11d1082001730d4b536d23c93382ec321128
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Oct 11 11:01:59 2012 +0000

    Add ability to use regexp's for expect in HTTP.

diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index 4f084ad..fa3ae3b 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -40,6 +40,7 @@
 
 #include "vct.h"
 #include "vgz.h"
+#include "vre.h"
 #include "vtcp.h"
 
 #define MAX_HDR		50
@@ -213,6 +214,10 @@ cmd_http_expect(CMD_ARGS)
 	const char *lhs;
 	char *cmp;
 	const char *rhs;
+	vre_t *vre;
+	const char *error;
+	int erroroffset;
+	int i;
 
 	(void)cmd;
 	(void)vl;
@@ -241,6 +246,19 @@ cmd_http_expect(CMD_ARGS)
 		else
 			vtc_log(hp->vl, 4, "EXPECT %s (%s) %s %s (%s) match",
 			    av[0], lhs, av[1], av[2], rhs);
+	} else if (!strcmp(cmp, "~") || !strcmp(cmp, "!~")) {
+		vre = VRE_compile(rhs, 0, &error, &erroroffset);
+		if (vre == NULL)
+			vtc_log(hp->vl, 0, "REGEXP error: %s (@%d) (%s)",
+			    error, erroroffset, rhs);
+		i = VRE_exec(vre, lhs, strlen(lhs), 0, 0, NULL, 0, 0);
+		if ((i >= 0 && *cmp == '~') || (i < 0 && *cmp == '!')) 
+			vtc_log(hp->vl, 4, "EXPECT %s (%s) %s \"%s\" match",
+			    av[0], lhs, cmp, rhs);
+		else
+			vtc_log(hp->vl, 0, "EXPECT %s (%s) %s \"%s\" failed",
+			    av[0], lhs, cmp, rhs);
+		VRE_free(&vre);
 	} else {
 		vtc_log(hp->vl, 0,
 		    "EXPECT %s (%s) %s %s (%s) test not implemented",



More information about the varnish-commit mailing list