[master] 7251861 Add std.syntax() to check if we run at a certain VCL level
Poul-Henning Kamp
phk at FreeBSD.org
Wed Feb 7 08:30:15 UTC 2018
commit 725186156f262c3d52f5355ae86acd6ee83ed3b9
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Feb 7 08:21:26 2018 +0000
Add std.syntax() to check if we run at a certain VCL level
diff --git a/bin/varnishtest/tests/m00001.vtc b/bin/varnishtest/tests/m00001.vtc
index a32a7de..7c79f89 100644
--- a/bin/varnishtest/tests/m00001.vtc
+++ b/bin/varnishtest/tests/m00001.vtc
@@ -5,12 +5,15 @@ server s1 {
txresp -hdr "foo: bAr" -hdr "bar: fOo" -bodylen 4
} -start
-varnish v1 -vcl+backend {
+varnish v1 -syntax 4.1 -vcl+backend {
import std;
sub vcl_deliver {
set resp.http.foo = std.toupper(resp.http.foo);
set resp.http.bar = std.tolower(resp.http.bar);
+ set resp.http.vcl40 = std.syntax(4.0);
+ set resp.http.vcl41 = std.syntax(4.1);
+ set resp.http.vcl42 = std.syntax(4.2);
std.set_ip_tos(32);
}
} -start
@@ -24,9 +27,19 @@ client c1 {
expect resp.bodylen == "4"
expect resp.http.foo == "BAR"
expect resp.http.bar == "foo"
+ expect resp.http.vcl40 == "true"
+ expect resp.http.vcl41 == "true"
+ expect resp.http.vcl42 == "false"
} -run
-varnish v1 -vcl+backend {
+varnish v1 -syntax 4.0 -vcl+backend {
+ import std;
+
+ sub vcl_deliver {
+ set resp.http.vcl40 = std.syntax(4.0);
+ set resp.http.vcl41 = std.syntax(4.1);
+ set resp.http.vcl42 = std.syntax(4.2);
+ }
}
client c1 {
@@ -36,14 +49,20 @@ client c1 {
expect resp.bodylen == "4"
expect resp.http.foo == "bAr"
expect resp.http.bar == "fOo"
+ expect resp.http.vcl40 == "true"
+ expect resp.http.vcl41 == "false"
+ expect resp.http.vcl42 == "false"
} -run
+varnish v1 -vcl+backend { }
+
varnish v1 -cliok "debug.vmod"
varnish v1 -cliok "vcl.list"
varnish v1 -expect vmods == 1
varnish v1 -cliok "vcl.discard vcl1"
+varnish v1 -cliok "vcl.discard vcl2"
varnish v1 -cliok "vcl.list"
varnish v1 -cliok "debug.vmod"
diff --git a/lib/libvmod_std/vmod.vcc b/lib/libvmod_std/vmod.vcc
index 7c2ed1d..e7c13a4 100644
--- a/lib/libvmod_std/vmod.vcc
+++ b/lib/libvmod_std/vmod.vcc
@@ -338,6 +338,11 @@ Example
| ...
| }
+$Function BOOL issyntax(REAL)
+
+Description
+ Returns the true if VCL version is at least REAL.
+
SEE ALSO
========
diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c
index 414a521..efd6d84 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -285,3 +285,17 @@ vmod_late_100_continue(VRT_CTX, VCL_BOOL late)
if (ctx->req->want100cont)
ctx->req->late100cont = late;
}
+
+VCL_BOOL v_matchproto_(td_std_syntax)
+vmod_syntax(VRT_CTX, VCL_REAL r)
+{
+
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ assert(ctx->syntax == 40 || ctx->syntax == 41);
+ /*
+ * We need to be careful because non-integer numbers have imprecise
+ * IEE754 represenation (4.1 is 0x1.0666666666666p+2 = 4.09999...)
+ * By scaling up and rounding, this is taken care of.
+ */
+ return (round(r * 10) <= ctx->syntax);
+}
More information about the varnish-commit
mailing list