[master] 41ad2c65e Teach VCC to do modules on INT, this is handy in vcl_synth{}:
Poul-Henning Kamp
phk at FreeBSD.org
Tue Feb 16 14:16:06 UTC 2021
commit 41ad2c65ec2550242f7f85a0ab5cc85d420b53a3
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Feb 16 13:55:11 2021 +0000
Teach VCC to do modules on INT, this is handy in vcl_synth{}:
sub vcl_synth {
if (resp.status == 12404) {
[...] // this specific 404
} else if (resp.status % 1000 == 404) {
[...] // all other 404's
}
}
diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc
index c9d41647b..9f93b241d 100644
--- a/bin/varnishtest/tests/v00020.vtc
+++ b/bin/varnishtest/tests/v00020.vtc
@@ -56,6 +56,13 @@ varnish v1 -errvcl {BOOL + BOOL not possible.} {
}
}
+varnish v1 -errvcl {Operator % only possible on INT} {
+ sub vcl_recv {
+ if (req.ttl % 1000) {
+ }
+ }
+}
+
varnish v1 -vcl {
backend b { .host = "${localhost}"; }
sub vcl_recv {
diff --git a/bin/varnishtest/tests/v00050.vtc b/bin/varnishtest/tests/v00050.vtc
index f4ab7acfe..b2529ed1e 100644
--- a/bin/varnishtest/tests/v00050.vtc
+++ b/bin/varnishtest/tests/v00050.vtc
@@ -123,6 +123,7 @@ varnish v1 -vcl+backend {
}
set resp.status = 22302;
set resp.reason = "Wrong Postcode";
+ set resp.http.residual = resp.status % 10000;
return (deliver);
}
} -start
@@ -159,6 +160,7 @@ client c1 {
txreq -url "/synth"
rxresp
expect resp.status == 302
+ expect resp.http.residual == 2302
expect resp.reason == "Wrong Postcode"
} -run
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index c15203caf..a8b91560a 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -911,13 +911,20 @@ vcc_expr_mul(struct vcc *tl, struct expr **e, vcc_type_t fmt)
struct expr *e2;
vcc_type_t f2;
struct token *tk;
+ char buf[24];
*e = NULL;
vcc_expr4(tl, e, fmt);
ERRCHK(tl);
AN(*e);
- while (tl->t->tok == '*' || tl->t->tok == '/') {
+ while (tl->t->tok == '*' || tl->t->tok == '/' || tl->t->tok == '%') {
+ if (tl->t->tok == '%' && ((*e)->fmt != INT)) {
+ VSB_printf(tl->sb,
+ "Operator %% only possible on INT.\n");
+ vcc_ErrWhere(tl, tl->t);
+ return;
+ }
f2 = (*e)->fmt->multype;
if (f2 == NULL) {
VSB_printf(tl->sb,
@@ -936,10 +943,8 @@ vcc_expr_mul(struct vcc *tl, struct expr **e, vcc_type_t fmt)
vcc_ErrWhere(tl, tk);
return;
}
- if (tk->tok == '*')
- *e = vcc_expr_edit(tl, (*e)->fmt, "(\v1*\v2)", *e, e2);
- else
- *e = vcc_expr_edit(tl, (*e)->fmt, "(\v1/\v2)", *e, e2);
+ bprintf(buf, "(\v1%c\v2)", tk->tok);
+ *e = vcc_expr_edit(tl, (*e)->fmt, buf, *e, e2);
}
}
More information about the varnish-commit
mailing list