blob: 8a04718b477d812d9df0cf7447327a52b5a7ff8b [file] [log] [blame]
Willy Tarreau9fdf3422021-03-26 14:03:57 +01001varnishtest "Test a few set-var() in global, tcp and http rule sets, at different scopes"
Willy Tarreau9a621ae2021-09-02 21:00:38 +02002feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.5-dev5)'"
Willy Tarreau9fdf3422021-03-26 14:03:57 +01003
4feature ignore_unknown_macro
5
6haproxy h1 -conf {
7 global
Willy Tarreau54496a62021-09-03 12:00:13 +02008 # note below, str60 is purposely not defined so that the default is used
Willy Tarreau9fdf3422021-03-26 14:03:57 +01009 set-var proc.int12 int(12)
Willy Tarreau54496a62021-09-03 12:00:13 +020010 set-var proc.int5 var(proc.str60,60),div(proc.int12)
Willy Tarreau9a621ae2021-09-02 21:00:38 +020011 set-var proc.str1 str("this is")
12 set-var proc.str2 str("a string")
13 set-var proc.str var(proc.str1)
Willy Tarreau753d4db2021-09-03 09:02:47 +020014 set-var-fmt proc.str "%[var(proc.str)] a string"
Willy Tarreau9fdf3422021-03-26 14:03:57 +010015 set-var proc.uuid uuid()
16
17 defaults
18 mode http
19 timeout connect 1s
20 timeout client 1s
21 timeout server 1s
22
23 frontend fe1
24 bind "fd@${fe1}"
Willy Tarreau9a621ae2021-09-02 21:00:38 +020025 tcp-request session set-var-fmt(sess.str3) "%[var(proc.str1)] %[var(proc.str2)]"
Willy Tarreau9fdf3422021-03-26 14:03:57 +010026 tcp-request session set-var(sess.int5) var(proc.int5)
27 tcp-request session set-var(proc.int5) var(proc.int5),add(sess.int5) ## proc. becomes 10
Willy Tarreau9a621ae2021-09-02 21:00:38 +020028 tcp-request content set-var-fmt(req.str4) "%[var(sess.str3),regsub(is a,is also a)]"
29 http-request set-var-fmt(txn.str5) "%[var(req.str4)]"
Willy Tarreau9fdf3422021-03-26 14:03:57 +010030 http-request set-var(req.int5) var(sess.int5)
31 http-request set-var(sess.int5) var(sess.int5),add(req.int5) ## sess. becomes 10 first time, then 15...
Willy Tarreau9a621ae2021-09-02 21:00:38 +020032 http-request return status 200 hdr x-var "proc=%[var(proc.int5)] sess=%[var(sess.int5)] req=%[var(req.int5)] str=%[var(proc.str)] str5=%[var(txn.str5)] uuid=%[var(proc.uuid)]"
Willy Tarreau9fdf3422021-03-26 14:03:57 +010033} -start
34
Willy Tarreauc35eb382021-03-26 14:51:31 +010035haproxy h1 -cli {
36 send "get var proc.int5"
37 expect ~ "^proc.int5: type=sint value=<5>$"
38}
39
Willy Tarreau9fdf3422021-03-26 14:03:57 +010040client c1 -connect ${h1_fe1_sock} {
41 txreq -req GET -url /req1_1
42 rxresp
43 expect resp.status == 200
Willy Tarreau9a621ae2021-09-02 21:00:38 +020044 expect resp.http.x-var ~ "proc=10 sess=10 req=5 str=this is a string str5=this is also a string uuid=[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*"
Willy Tarreau9fdf3422021-03-26 14:03:57 +010045
46 txreq -req GET -url /req1_2
47 rxresp
48 expect resp.status == 200
Willy Tarreau9a621ae2021-09-02 21:00:38 +020049 expect resp.http.x-var ~ "proc=10 sess=20 req=10 str=this is a string str5=this is also a string uuid=[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*"
Willy Tarreau9fdf3422021-03-26 14:03:57 +010050} -run
51
Willy Tarreauc35eb382021-03-26 14:51:31 +010052haproxy h1 -cli {
53 send "get var proc.int5"
54 expect ~ "^proc.int5: type=sint value=<10>$"
55}
56
Willy Tarreau9fdf3422021-03-26 14:03:57 +010057client c2 -connect ${h1_fe1_sock} {
58 txreq -req GET -url /req2_1
59 rxresp
60 expect resp.status == 200
Willy Tarreau9a621ae2021-09-02 21:00:38 +020061 expect resp.http.x-var ~ "proc=20 sess=20 req=10 str=this is a string str5=this is also a string uuid=[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*"
Willy Tarreau9fdf3422021-03-26 14:03:57 +010062
63 txreq -req GET -url /req2_2
64 rxresp
65 expect resp.status == 200
Willy Tarreau9a621ae2021-09-02 21:00:38 +020066 expect resp.http.x-var ~ "proc=20 sess=40 req=20 str=this is a string str5=this is also a string uuid=[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*"
Willy Tarreau9fdf3422021-03-26 14:03:57 +010067} -run
Willy Tarreauc35eb382021-03-26 14:51:31 +010068
69haproxy h1 -cli {
70 send "get var proc.int5"
71 expect ~ "^proc.int5: type=sint value=<20>$"
72}
Willy Tarreaub8bd1ee2021-03-26 15:19:50 +010073
74haproxy h1 -cli {
Willy Tarreaue93bff42021-09-03 09:47:37 +020075 send "experimental-mode on; set var proc.str str(updating); set var proc.str fmt %[var(proc.str),regsub(ing,ed)]"
Willy Tarreaub8bd1ee2021-03-26 15:19:50 +010076 expect ~ .*
77}
78
79client c3 -connect ${h1_fe1_sock} {
80 txreq -req GET -url /req3_1
81 rxresp
82 expect resp.status == 200
Willy Tarreau9a621ae2021-09-02 21:00:38 +020083 expect resp.http.x-var ~ "proc=40 sess=40 req=20 str=updated str5=this is also a string uuid=[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*"
Willy Tarreaub8bd1ee2021-03-26 15:19:50 +010084} -run