Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
72518615
Commit
72518615
authored
Feb 07, 2018
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add std.syntax() to check if we run at a certain VCL level
parent
20d84897
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
2 deletions
+40
-2
m00001.vtc
bin/varnishtest/tests/m00001.vtc
+21
-2
vmod.vcc
lib/libvmod_std/vmod.vcc
+5
-0
vmod_std.c
lib/libvmod_std/vmod_std.c
+14
-0
No files found.
bin/varnishtest/tests/m00001.vtc
View file @
72518615
...
...
@@ -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"
...
...
lib/libvmod_std/vmod.vcc
View file @
72518615
...
...
@@ -338,6 +338,11 @@ Example
| ...
| }
$Function BOOL issyntax(REAL)
Description
Returns the true if VCL version is at least REAL.
SEE ALSO
========
...
...
lib/libvmod_std/vmod_std.c
View file @
72518615
...
...
@@ -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
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment