blob: cc726ab08f1b35ac5c02e2a8b7bf5c87472ed282 [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
Christopher Faulet57962282022-04-25 14:30:58 +020095haproxy h3 -conf {
96 defaults base-http
97 mode http
98 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
99 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
100 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
101
102 http-request capture hdr(Host) len 64 # idx 0
103 http-request capture hdr(X-req-1) len 32 # idx 1
104
105 frontend fe1 from base-http
106 bind "fd@${fe1h3}"
107 declare capture request len 32 # idx 2
108
109 http-request capture hdr(X-req-2) id 2
110 http-request return status 200 hdr "X-Capture-1" "%[capture.req.hdr(0)]" hdr "X-Capture-2" "%[capture.req.hdr(1)]" hdr "X-Capture-3" "%[capture.req.hdr(2)]"
111
112 frontend fe2 from base-http
113 bind "fd@${fe2h3}"
114 http-request capture hdr(X-req-2) id 1
115 http-request return status 200 hdr "X-Capture-1" "%[capture.req.hdr(0)]" hdr "X-Capture-2" "%[capture.req.hdr(1)]"
116
117} -start
118
Christopher Faulete41b4972021-10-13 18:06:55 +0200119client c1 -connect ${h1_feh1_sock} {
120 txreq -req GET -url /
121 rxresp
122 expect resp.status == 200
123 expect resp.http.x-frontend == "fe"
124 expect resp.http.x-backend == "be"
125 expect resp.http.x-test2-bck == "def_back"
126 expect resp.http.x-test2-frt == "def_front"
127 expect resp.http.x-test3-bck == "def_back"
128 expect resp.http.x-test3-frt == "def_front"
129} -run
130
131client c2 -connect ${h2_feh2_sock} {
132 txreq -req GET -url /
133 rxresp
134 expect resp.status == 200
Christopher Faulet57962282022-04-25 14:30:58 +0200135} -run
136
137client c3 -connect ${h3_fe1h3_sock} {
138 txreq -req GET -url / \
139 -hdr "host: v-test" \
140 -hdr "x-req-1: val1" \
141 -hdr "x-req-2: val2"
142 rxresp
143 expect resp.status == 200
144 expect resp.http.x-capture-1 == "v-test"
145 expect resp.http.x-capture-2 == "val1"
146 expect resp.http.x-capture-3 == "val2"
147} -run
148
149client c4 -connect ${h3_fe2h3_sock} {
150 txreq -req GET -url / \
151 -hdr "host: v-test" \
152 -hdr "x-req-1: val1" \
153 -hdr "x-req-2: val2"
154 rxresp
155 expect resp.status == 200
156 expect resp.http.x-capture-1 == "v-test"
157 expect resp.http.x-capture-2 == "val2"
158 expect resp.http.x-capture-3 == "<undef>"
Christopher Faulete41b4972021-10-13 18:06:55 +0200159} -run