Willy Tarreau | 9fdf342 | 2021-03-26 14:03:57 +0100 | [diff] [blame] | 1 | varnishtest "Test a few set-var() in global, tcp and http rule sets, at different scopes" |
Willy Tarreau | 9a621ae | 2021-09-02 21:00:38 +0200 | [diff] [blame] | 2 | feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.5-dev5)'" |
Willy Tarreau | 9fdf342 | 2021-03-26 14:03:57 +0100 | [diff] [blame] | 3 | |
| 4 | feature ignore_unknown_macro |
| 5 | |
| 6 | haproxy h1 -conf { |
| 7 | global |
Willy Tarreau | 54496a6 | 2021-09-03 12:00:13 +0200 | [diff] [blame] | 8 | # note below, str60 is purposely not defined so that the default is used |
Willy Tarreau | 9fdf342 | 2021-03-26 14:03:57 +0100 | [diff] [blame] | 9 | set-var proc.int12 int(12) |
Willy Tarreau | 54496a6 | 2021-09-03 12:00:13 +0200 | [diff] [blame] | 10 | set-var proc.int5 var(proc.str60,60),div(proc.int12) |
Willy Tarreau | 9a621ae | 2021-09-02 21:00:38 +0200 | [diff] [blame] | 11 | set-var proc.str1 str("this is") |
| 12 | set-var proc.str2 str("a string") |
| 13 | set-var proc.str var(proc.str1) |
Willy Tarreau | 753d4db | 2021-09-03 09:02:47 +0200 | [diff] [blame] | 14 | set-var-fmt proc.str "%[var(proc.str)] a string" |
Willy Tarreau | 9fdf342 | 2021-03-26 14:03:57 +0100 | [diff] [blame] | 15 | 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 Tarreau | 9a621ae | 2021-09-02 21:00:38 +0200 | [diff] [blame] | 25 | tcp-request session set-var-fmt(sess.str3) "%[var(proc.str1)] %[var(proc.str2)]" |
Willy Tarreau | 9fdf342 | 2021-03-26 14:03:57 +0100 | [diff] [blame] | 26 | 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 Tarreau | 9a621ae | 2021-09-02 21:00:38 +0200 | [diff] [blame] | 28 | 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 Tarreau | 9fdf342 | 2021-03-26 14:03:57 +0100 | [diff] [blame] | 30 | 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 Tarreau | 9a621ae | 2021-09-02 21:00:38 +0200 | [diff] [blame] | 32 | 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 Tarreau | 9fdf342 | 2021-03-26 14:03:57 +0100 | [diff] [blame] | 33 | } -start |
| 34 | |
Willy Tarreau | c35eb38 | 2021-03-26 14:51:31 +0100 | [diff] [blame] | 35 | haproxy h1 -cli { |
| 36 | send "get var proc.int5" |
| 37 | expect ~ "^proc.int5: type=sint value=<5>$" |
| 38 | } |
| 39 | |
Willy Tarreau | 9fdf342 | 2021-03-26 14:03:57 +0100 | [diff] [blame] | 40 | client c1 -connect ${h1_fe1_sock} { |
| 41 | txreq -req GET -url /req1_1 |
| 42 | rxresp |
| 43 | expect resp.status == 200 |
Willy Tarreau | 9a621ae | 2021-09-02 21:00:38 +0200 | [diff] [blame] | 44 | 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 Tarreau | 9fdf342 | 2021-03-26 14:03:57 +0100 | [diff] [blame] | 45 | |
| 46 | txreq -req GET -url /req1_2 |
| 47 | rxresp |
| 48 | expect resp.status == 200 |
Willy Tarreau | 9a621ae | 2021-09-02 21:00:38 +0200 | [diff] [blame] | 49 | 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 Tarreau | 9fdf342 | 2021-03-26 14:03:57 +0100 | [diff] [blame] | 50 | } -run |
| 51 | |
Willy Tarreau | c35eb38 | 2021-03-26 14:51:31 +0100 | [diff] [blame] | 52 | haproxy h1 -cli { |
| 53 | send "get var proc.int5" |
| 54 | expect ~ "^proc.int5: type=sint value=<10>$" |
| 55 | } |
| 56 | |
Willy Tarreau | 9fdf342 | 2021-03-26 14:03:57 +0100 | [diff] [blame] | 57 | client c2 -connect ${h1_fe1_sock} { |
| 58 | txreq -req GET -url /req2_1 |
| 59 | rxresp |
| 60 | expect resp.status == 200 |
Willy Tarreau | 9a621ae | 2021-09-02 21:00:38 +0200 | [diff] [blame] | 61 | 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 Tarreau | 9fdf342 | 2021-03-26 14:03:57 +0100 | [diff] [blame] | 62 | |
| 63 | txreq -req GET -url /req2_2 |
| 64 | rxresp |
| 65 | expect resp.status == 200 |
Willy Tarreau | 9a621ae | 2021-09-02 21:00:38 +0200 | [diff] [blame] | 66 | 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 Tarreau | 9fdf342 | 2021-03-26 14:03:57 +0100 | [diff] [blame] | 67 | } -run |
Willy Tarreau | c35eb38 | 2021-03-26 14:51:31 +0100 | [diff] [blame] | 68 | |
| 69 | haproxy h1 -cli { |
| 70 | send "get var proc.int5" |
| 71 | expect ~ "^proc.int5: type=sint value=<20>$" |
| 72 | } |
Willy Tarreau | b8bd1ee | 2021-03-26 15:19:50 +0100 | [diff] [blame] | 73 | |
| 74 | haproxy h1 -cli { |
Willy Tarreau | e93bff4 | 2021-09-03 09:47:37 +0200 | [diff] [blame] | 75 | send "experimental-mode on; set var proc.str str(updating); set var proc.str fmt %[var(proc.str),regsub(ing,ed)]" |
Willy Tarreau | b8bd1ee | 2021-03-26 15:19:50 +0100 | [diff] [blame] | 76 | expect ~ .* |
| 77 | } |
| 78 | |
| 79 | client c3 -connect ${h1_fe1_sock} { |
| 80 | txreq -req GET -url /req3_1 |
| 81 | rxresp |
| 82 | expect resp.status == 200 |
Willy Tarreau | 9a621ae | 2021-09-02 21:00:38 +0200 | [diff] [blame] | 83 | 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 Tarreau | b8bd1ee | 2021-03-26 15:19:50 +0100 | [diff] [blame] | 84 | } -run |