Commit 72518615 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add std.syntax() to check if we run at a certain VCL level

parent 20d84897
......@@ -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"
......
......@@ -338,6 +338,11 @@ Example
| ...
| }
$Function BOOL issyntax(REAL)
Description
Returns the true if VCL version is at least REAL.
SEE ALSO
========
......
......@@ -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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment