Tim Duesterhus | 84ebc13 | 2020-05-19 13:49:41 +0200 | [diff] [blame] | 1 | varnishtest "Lua: set_var" |
Christopher Faulet | 80f59e5 | 2020-05-26 11:11:23 +0200 | [diff] [blame] | 2 | #REQUIRE_VERSION=2.2 |
Tim Duesterhus | 84ebc13 | 2020-05-19 13:49:41 +0200 | [diff] [blame] | 3 | #REQUIRE_OPTIONS=LUA |
| 4 | |
| 5 | feature ignore_unknown_macro |
| 6 | |
| 7 | haproxy h1 -conf { |
| 8 | global |
Willy Tarreau | e1465c1 | 2021-05-09 14:41:41 +0200 | [diff] [blame] | 9 | # WT: limit false-positives causing "HTTP header incomplete" due to |
| 10 | # idle server connections being randomly used and randomly expiring |
| 11 | # under us. |
| 12 | tune.idle-pool.shared off |
| 13 | |
| 14 | global |
Tim Duesterhus | 84ebc13 | 2020-05-19 13:49:41 +0200 | [diff] [blame] | 15 | lua-load ${testdir}/set_var.lua |
| 16 | |
| 17 | frontend fe1 |
| 18 | mode http |
Tim Duesterhus | 84ebc13 | 2020-05-19 13:49:41 +0200 | [diff] [blame] | 19 | bind "fd@${fe1}" |
| 20 | |
| 21 | http-request use-service lua.set_var |
Tim Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 22 | |
| 23 | frontend fe2 |
| 24 | mode http |
Tim Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 25 | bind "fd@${fe2}" |
| 26 | |
| 27 | http-request set-header Dummy %[var(txn.fe2_foo)] |
| 28 | |
| 29 | http-request use-service lua.set_var_ifexist |
Tim Duesterhus | 84ebc13 | 2020-05-19 13:49:41 +0200 | [diff] [blame] | 30 | } -start |
| 31 | |
| 32 | client c0 -connect ${h1_fe1_sock} { |
| 33 | txreq -url "/" \ |
Tim Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 34 | -hdr "Var: txn.fe1_foo" |
Tim Duesterhus | 84ebc13 | 2020-05-19 13:49:41 +0200 | [diff] [blame] | 35 | rxresp |
| 36 | expect resp.status == 202 |
| 37 | expect resp.http.echo == "value" |
| 38 | txreq -url "/" \ |
| 39 | -hdr "Var: invalid.var" |
| 40 | rxresp |
| 41 | expect resp.status == 400 |
| 42 | expect resp.http.echo == "(nil)" |
| 43 | } -run |
Tim Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 44 | |
| 45 | client c1 -connect ${h1_fe2_sock} { |
| 46 | txreq -url "/" \ |
| 47 | -hdr "Var: txn.fe2_foo" |
| 48 | rxresp |
| 49 | expect resp.status == 202 |
| 50 | expect resp.http.echo == "value" |
| 51 | txreq -url "/" \ |
| 52 | -hdr "Var: txn.fe2_bar" |
| 53 | rxresp |
| 54 | expect resp.status == 400 |
| 55 | expect resp.http.echo == "(nil)" |
| 56 | } -run |