blob: f4a8fb9d25215ae65b59c77892cdaa6c132d5b88 [file] [log] [blame]
Christopher Faulete41b4972021-10-13 18:06:55 +02001varnishtest "Test declaration of HTTP rules in default sections"
2
Tim Duesterhus41922af2021-11-04 21:12:14 +01003feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.5-dev0)'"
Christopher Faulete41b4972021-10-13 18:06:55 +02004feature ignore_unknown_macro
5
6server s1 {
7 rxreq
8 expect req.http.x-frontend == "fe"
9 expect req.http.x-backend == "be"
10 expect req.http.x-test1-frt == "def_front"
11 expect req.http.x-test1-bck == "def_back"
12 txresp
13} -start
14
15server s2 {
16 rxreq
17 txresp
18} -start
19
20haproxy h1 -conf {
21 defaults common
22 mode http
Willy Tarreauf6739232021-11-18 17:46:22 +010023 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
24 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
25 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
Christopher Faulete41b4972021-10-13 18:06:55 +020026
27 defaults def_front from common
28 http-request set-header x-frontend "%[fe_name]"
29 http-request set-var(txn.test1) "str(def_front)"
30 http-response set-header x-frontend "%[fe_name]"
31 http-response set-var(txn.test2) "str(def_front)"
32 http-after-response set-var(txn.test3) "str(def_front)"
33
34 defaults def_back from common
35 http-request set-header x-backend "%[be_name]"
36 http-request set-var(txn.test1) "str(def_back)"
37 http-response set-header x-backend "%[be_name]"
38 http-response set-var(txn.test2) "str(def_back)"
39 http-after-response set-var(txn.test3) "str(def_back)"
40
41 frontend fe from def_front
42 bind "fd@${feh1}"
43
44 http-request set-header x-test1-frt "%[var(txn.test1)]"
45 http-response set-header x-test2-frt "%[var(txn.test2)]"
46 http-after-response set-header x-test3-frt "%[var(txn.test3)]"
47
48 default_backend be
49
50 backend be from def_back
51 http-request set-header x-test1-bck "%[var(txn.test1)]"
52 http-response set-header x-test2-bck "%[var(txn.test2)]"
53 http-after-response set-header x-test3-bck "%[var(txn.test3)]"
54
55 server s1 ${s1_addr}:${s1_port}
56
57} -start
58
59
60haproxy h2 -conf {
61 defaults common
62 mode http
Willy Tarreauf6739232021-11-18 17:46:22 +010063 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
64 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
65 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
Christopher Faulete41b4972021-10-13 18:06:55 +020066
67 defaults def_front from common
68 http-request allow
69 http-response allow
70 http-after-response allow
71
72 defaults def_back from common
73 http-request allow
74 http-response allow
75 http-after-response allow
76
77 frontend fe from def_front
78 bind "fd@${feh2}"
79
80 http-request deny status 403
81 http-response deny status 502
82 http-after-response set-status 502
83
84 default_backend be
85
86 backend be from def_back
87 http-request deny status 403
88 http-response deny status 502
89 http-after-response set-status 502
90
91 server s2 ${s2_addr}:${s2_port}
92
93} -start
94
95client c1 -connect ${h1_feh1_sock} {
96 txreq -req GET -url /
97 rxresp
98 expect resp.status == 200
99 expect resp.http.x-frontend == "fe"
100 expect resp.http.x-backend == "be"
101 expect resp.http.x-test2-bck == "def_back"
102 expect resp.http.x-test2-frt == "def_front"
103 expect resp.http.x-test3-bck == "def_back"
104 expect resp.http.x-test3-frt == "def_front"
105} -run
106
107client c2 -connect ${h2_feh2_sock} {
108 txreq -req GET -url /
109 rxresp
110 expect resp.status == 200
111} -run