blob: 95ab68d89130ebf0b2155add5c114fbf26697875 [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
8 set-var proc.int12 int(12)
9 set-var proc.int5 str(60),div(proc.int12)
Willy Tarreau9a621ae2021-09-02 21:00:38 +020010 set-var proc.str1 str("this is")
11 set-var proc.str2 str("a string")
12 set-var proc.str var(proc.str1)
Willy Tarreau9fdf3422021-03-26 14:03:57 +010013 set-var proc.str str(""),concat("",proc.str," a string")
14 set-var proc.uuid uuid()
15
16 defaults
17 mode http
18 timeout connect 1s
19 timeout client 1s
20 timeout server 1s
21
22 frontend fe1
23 bind "fd@${fe1}"
Willy Tarreau9a621ae2021-09-02 21:00:38 +020024 tcp-request session set-var-fmt(sess.str3) "%[var(proc.str1)] %[var(proc.str2)]"
Willy Tarreau9fdf3422021-03-26 14:03:57 +010025 tcp-request session set-var(sess.int5) var(proc.int5)
26 tcp-request session set-var(proc.int5) var(proc.int5),add(sess.int5) ## proc. becomes 10
Willy Tarreau9a621ae2021-09-02 21:00:38 +020027 tcp-request content set-var-fmt(req.str4) "%[var(sess.str3),regsub(is a,is also a)]"
28 http-request set-var-fmt(txn.str5) "%[var(req.str4)]"
Willy Tarreau9fdf3422021-03-26 14:03:57 +010029 http-request set-var(req.int5) var(sess.int5)
30 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 +020031 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 +010032} -start
33
Willy Tarreauc35eb382021-03-26 14:51:31 +010034haproxy h1 -cli {
35 send "get var proc.int5"
36 expect ~ "^proc.int5: type=sint value=<5>$"
37}
38
Willy Tarreau9fdf3422021-03-26 14:03:57 +010039client c1 -connect ${h1_fe1_sock} {
40 txreq -req GET -url /req1_1
41 rxresp
42 expect resp.status == 200
Willy Tarreau9a621ae2021-09-02 21:00:38 +020043 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 +010044
45 txreq -req GET -url /req1_2
46 rxresp
47 expect resp.status == 200
Willy Tarreau9a621ae2021-09-02 21:00:38 +020048 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 +010049} -run
50
Willy Tarreauc35eb382021-03-26 14:51:31 +010051haproxy h1 -cli {
52 send "get var proc.int5"
53 expect ~ "^proc.int5: type=sint value=<10>$"
54}
55
Willy Tarreau9fdf3422021-03-26 14:03:57 +010056client c2 -connect ${h1_fe1_sock} {
57 txreq -req GET -url /req2_1
58 rxresp
59 expect resp.status == 200
Willy Tarreau9a621ae2021-09-02 21:00:38 +020060 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 +010061
62 txreq -req GET -url /req2_2
63 rxresp
64 expect resp.status == 200
Willy Tarreau9a621ae2021-09-02 21:00:38 +020065 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 +010066} -run
Willy Tarreauc35eb382021-03-26 14:51:31 +010067
68haproxy h1 -cli {
69 send "get var proc.int5"
70 expect ~ "^proc.int5: type=sint value=<20>$"
71}
Willy Tarreaub8bd1ee2021-03-26 15:19:50 +010072
73haproxy h1 -cli {
74 send "experimental-mode on; set var proc.str str(updated)"
75 expect ~ .*
76}
77
78client c3 -connect ${h1_fe1_sock} {
79 txreq -req GET -url /req3_1
80 rxresp
81 expect resp.status == 200
Willy Tarreau9a621ae2021-09-02 21:00:38 +020082 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 +010083} -run