2021-03-26 13:03:57 +00:00
varnishtest "Test a few set-var() in global, tcp and http rule sets, at different scopes"
2021-09-02 19:00:38 +00:00
feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.5-dev5)'"
2021-03-26 13:03:57 +00:00
feature ignore_unknown_macro
haproxy h1 -conf {
global
2021-09-03 10:00:13 +00:00
# note below, str60 is purposely not defined so that the default is used
2021-03-26 13:03:57 +00:00
set-var proc.int12 int(12)
2021-09-03 10:00:13 +00:00
set-var proc.int5 var(proc.str60,60),div(proc.int12)
2021-09-02 19:00:38 +00:00
set-var proc.str1 str("this is")
set-var proc.str2 str("a string")
set-var proc.str var(proc.str1)
2021-09-03 07:02:47 +00:00
set-var-fmt proc.str "%[var(proc.str)] a string"
2021-03-26 13:03:57 +00:00
set-var proc.uuid uuid()
defaults
mode http
2021-11-18 16:46:22 +00:00
timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
2021-03-26 13:03:57 +00:00
frontend fe1
bind "fd@${fe1}"
2021-09-02 19:00:38 +00:00
tcp-request session set-var-fmt(sess.str3) "%[var(proc.str1)] %[var(proc.str2)]"
2021-03-26 13:03:57 +00:00
tcp-request session set-var(sess.int5) var(proc.int5)
tcp-request session set-var(proc.int5) var(proc.int5),add(sess.int5) ## proc. becomes 10
2021-09-02 19:00:38 +00:00
tcp-request content set-var-fmt(req.str4) "%[var(sess.str3),regsub(is a,is also a)]"
http-request set-var-fmt(txn.str5) "%[var(req.str4)]"
2021-03-26 13:03:57 +00:00
http-request set-var(req.int5) var(sess.int5)
http-request set-var(sess.int5) var(sess.int5),add(req.int5) ## sess. becomes 10 first time, then 15...
2021-09-02 19:00:38 +00:00
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)]"
2021-03-26 13:03:57 +00:00
} -start
2021-03-26 13:51:31 +00:00
haproxy h1 -cli {
send "get var proc.int5"
expect ~ "^proc.int5: type=sint value=<5>$"
}
2021-03-26 13:03:57 +00:00
client c1 -connect ${h1_fe1_sock} {
txreq -req GET -url /req1_1
rxresp
expect resp.status == 200
2021-09-02 19:00:38 +00:00
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]*"
2021-03-26 13:03:57 +00:00
txreq -req GET -url /req1_2
rxresp
expect resp.status == 200
2021-09-02 19:00:38 +00:00
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]*"
2021-03-26 13:03:57 +00:00
} -run
2021-03-26 13:51:31 +00:00
haproxy h1 -cli {
send "get var proc.int5"
expect ~ "^proc.int5: type=sint value=<10>$"
}
2021-03-26 13:03:57 +00:00
client c2 -connect ${h1_fe1_sock} {
txreq -req GET -url /req2_1
rxresp
expect resp.status == 200
2021-09-02 19:00:38 +00:00
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]*"
2021-03-26 13:03:57 +00:00
txreq -req GET -url /req2_2
rxresp
expect resp.status == 200
2021-09-02 19:00:38 +00:00
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]*"
2021-03-26 13:03:57 +00:00
} -run
2021-03-26 13:51:31 +00:00
haproxy h1 -cli {
send "get var proc.int5"
expect ~ "^proc.int5: type=sint value=<20>$"
}
2021-03-26 14:19:50 +00:00
haproxy h1 -cli {
2021-09-03 07:47:37 +00:00
send "experimental-mode on; set var proc.str str(updating); set var proc.str fmt %[var(proc.str),regsub(ing,ed)]"
2021-03-26 14:19:50 +00:00
expect ~ .*
}
client c3 -connect ${h1_fe1_sock} {
txreq -req GET -url /req3_1
rxresp
expect resp.status == 200
2021-09-02 19:00:38 +00:00
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]*"
2021-03-26 14:19:50 +00:00
} -run