blob: 01e25b96d86f6d2c5bd4b2e6b4baf9c8f7c02485 [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"
2#REQUIRE_VERSION=2.4
3
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)
10 set-var proc.str str("this is")
11 set-var proc.str str(""),concat("",proc.str," a string")
12 set-var proc.uuid uuid()
13
14 defaults
15 mode http
16 timeout connect 1s
17 timeout client 1s
18 timeout server 1s
19
20 frontend fe1
21 bind "fd@${fe1}"
22 tcp-request session set-var(sess.int5) var(proc.int5)
23 tcp-request session set-var(proc.int5) var(proc.int5),add(sess.int5) ## proc. becomes 10
24 http-request set-var(req.int5) var(sess.int5)
25 http-request set-var(sess.int5) var(sess.int5),add(req.int5) ## sess. becomes 10 first time, then 15...
26 http-request return status 200 hdr x-var "proc=%[var(proc.int5)] sess=%[var(sess.int5)] req=%[var(req.int5)] str=%[var(proc.str)] uuid=%[var(proc.uuid)]"
27} -start
28
Willy Tarreauc35eb382021-03-26 14:51:31 +010029haproxy h1 -cli {
30 send "get var proc.int5"
31 expect ~ "^proc.int5: type=sint value=<5>$"
32}
33
Willy Tarreau9fdf3422021-03-26 14:03:57 +010034client c1 -connect ${h1_fe1_sock} {
35 txreq -req GET -url /req1_1
36 rxresp
37 expect resp.status == 200
38 expect resp.http.x-var ~ "proc=10 sess=10 req=5 str=this is a string uuid=[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*"
39
40 txreq -req GET -url /req1_2
41 rxresp
42 expect resp.status == 200
43 expect resp.http.x-var ~ "proc=10 sess=20 req=10 str=this is a string uuid=[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*"
44} -run
45
Willy Tarreauc35eb382021-03-26 14:51:31 +010046haproxy h1 -cli {
47 send "get var proc.int5"
48 expect ~ "^proc.int5: type=sint value=<10>$"
49}
50
Willy Tarreau9fdf3422021-03-26 14:03:57 +010051client c2 -connect ${h1_fe1_sock} {
52 txreq -req GET -url /req2_1
53 rxresp
54 expect resp.status == 200
55 expect resp.http.x-var ~ "proc=20 sess=20 req=10 str=this is a string uuid=[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*"
56
57 txreq -req GET -url /req2_2
58 rxresp
59 expect resp.status == 200
60 expect resp.http.x-var ~ "proc=20 sess=40 req=20 str=this is a string uuid=[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*"
61} -run
Willy Tarreauc35eb382021-03-26 14:51:31 +010062
63haproxy h1 -cli {
64 send "get var proc.int5"
65 expect ~ "^proc.int5: type=sint value=<20>$"
66}
Willy Tarreaub8bd1ee2021-03-26 15:19:50 +010067
68haproxy h1 -cli {
69 send "experimental-mode on; set var proc.str str(updated)"
70 expect ~ .*
71}
72
73client c3 -connect ${h1_fe1_sock} {
74 txreq -req GET -url /req3_1
75 rxresp
76 expect resp.status == 200
77 expect resp.http.x-var ~ "proc=40 sess=40 req=20 str=updated uuid=[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*"
78} -run