blob: 5ca49b6bf519076b3a0c9f7f142185c38057523d [file] [log] [blame]
Tim Duesterhus84ebc132020-05-19 13:49:41 +02001varnishtest "Lua: set_var"
Christopher Faulet80f59e52020-05-26 11:11:23 +02002#REQUIRE_VERSION=2.2
Tim Duesterhus84ebc132020-05-19 13:49:41 +02003#REQUIRE_OPTIONS=LUA
4
5feature ignore_unknown_macro
6
7haproxy h1 -conf {
8 global
Willy Tarreaue1465c12021-05-09 14:41:41 +02009 # 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 Duesterhus84ebc132020-05-19 13:49:41 +020015 lua-load ${testdir}/set_var.lua
16
17 frontend fe1
18 mode http
Tim Duesterhus84ebc132020-05-19 13:49:41 +020019 bind "fd@${fe1}"
20
21 http-request use-service lua.set_var
Tim Duesterhus4e172c92020-05-19 13:49:42 +020022
23 frontend fe2
24 mode http
Tim Duesterhus4e172c92020-05-19 13:49:42 +020025 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 Duesterhus84ebc132020-05-19 13:49:41 +020030} -start
31
32client c0 -connect ${h1_fe1_sock} {
33 txreq -url "/" \
Tim Duesterhus4e172c92020-05-19 13:49:42 +020034 -hdr "Var: txn.fe1_foo"
Tim Duesterhus84ebc132020-05-19 13:49:41 +020035 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 Duesterhus4e172c92020-05-19 13:49:42 +020044
45client 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