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