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 |
| 19 | ${no-htx} option http-use-htx |
| 20 | bind "fd@${fe1}" |
| 21 | |
| 22 | http-request use-service lua.set_var |
Tim Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 23 | |
| 24 | frontend fe2 |
| 25 | mode http |
| 26 | ${no-htx} option http-use-htx |
| 27 | bind "fd@${fe2}" |
| 28 | |
| 29 | http-request set-header Dummy %[var(txn.fe2_foo)] |
| 30 | |
| 31 | http-request use-service lua.set_var_ifexist |
Tim Duesterhus | 84ebc13 | 2020-05-19 13:49:41 +0200 | [diff] [blame] | 32 | } -start |
| 33 | |
| 34 | client c0 -connect ${h1_fe1_sock} { |
| 35 | txreq -url "/" \ |
Tim Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 36 | -hdr "Var: txn.fe1_foo" |
Tim Duesterhus | 84ebc13 | 2020-05-19 13:49:41 +0200 | [diff] [blame] | 37 | rxresp |
| 38 | expect resp.status == 202 |
| 39 | expect resp.http.echo == "value" |
| 40 | txreq -url "/" \ |
| 41 | -hdr "Var: invalid.var" |
| 42 | rxresp |
| 43 | expect resp.status == 400 |
| 44 | expect resp.http.echo == "(nil)" |
| 45 | } -run |
Tim Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 46 | |
| 47 | client c1 -connect ${h1_fe2_sock} { |
| 48 | txreq -url "/" \ |
| 49 | -hdr "Var: txn.fe2_foo" |
| 50 | rxresp |
| 51 | expect resp.status == 202 |
| 52 | expect resp.http.echo == "value" |
| 53 | txreq -url "/" \ |
| 54 | -hdr "Var: txn.fe2_bar" |
| 55 | rxresp |
| 56 | expect resp.status == 400 |
| 57 | expect resp.http.echo == "(nil)" |
| 58 | } -run |