[master] 831ca47f8 Add numeric comparisons for HTTP headers: -lt, -le, -eq, -ne, -ge, -gt

Poul-Henning Kamp phk at FreeBSD.org
Thu Feb 11 12:41:08 UTC 2021


commit 831ca47f8dae4abd9c6174a4339e86252d13288e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Feb 11 12:38:25 2021 +0000

    Add numeric comparisons for HTTP headers: -lt, -le, -eq, -ne, -ge, -gt
    
            expect  resp.http.content-length -le 1024

diff --git a/bin/varnishtest/vtc_subr.c b/bin/varnishtest/vtc_subr.c
index fe5fe2008..3eb60c100 100644
--- a/bin/varnishtest/vtc_subr.c
+++ b/bin/varnishtest/vtc_subr.c
@@ -33,6 +33,7 @@
 #include <sys/types.h>
 #include <math.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <stdint.h>
 #include <unistd.h>
@@ -109,6 +110,18 @@ vtc_expect(struct vtclog *vl,
 		retval = strcmp(lhs, rhs) == 0;
 	} else if (!strcmp(cmp, "!=")) {
 		retval = strcmp(lhs, rhs) != 0;
+	} else if (!strcmp(cmp, "-lt")) {
+		retval = strtoul(lhs, NULL, 0) < strtoul(rhs, NULL, 0);
+	} else if (!strcmp(cmp, "-le")) {
+		retval = strtoul(lhs, NULL, 0) <= strtoul(rhs, NULL, 0);
+	} else if (!strcmp(cmp, "-eq")) {
+		retval = strtoul(lhs, NULL, 0) == strtoul(rhs, NULL, 0);
+	} else if (!strcmp(cmp, "-ne")) {
+		retval = strtoul(lhs, NULL, 0) != strtoul(rhs, NULL, 0);
+	} else if (!strcmp(cmp, "-ge")) {
+		retval = strtoul(lhs, NULL, 0) >= strtoul(rhs, NULL, 0);
+	} else if (!strcmp(cmp, "-gt")) {
+		retval = strtoul(lhs, NULL, 0) > strtoul(rhs, NULL, 0);
 	} else if (j) {
 		// fail inequality comparisons if either side is undef'ed
 		retval = 0;


More information about the varnish-commit mailing list