blob: 0d6536698608e7f947095865f80e6bfcd50ce388 [file] [log] [blame]
Christopher Faulet8f161482018-12-19 11:49:39 +01001varnishtest "HTTP request tests: H1 to H1 (HTX mode supported only for HAProxy >= 1.9)"
Willy Tarreau7b8d2032018-12-13 19:35:29 +01002
3# Run it with HAPROXY_PROGRAM=$PWD/haproxy varnishtest -l -k -t 1 "$1"
4
5feature ignore_unknown_macro
6
7server s1 {
Christopher Fauletf7b941c2019-04-01 11:26:25 +02008 ##
9 ## Handle GET requests
10 ##
Willy Tarreau7b8d2032018-12-13 19:35:29 +010011 rxreq
Christopher Fauletf7b941c2019-04-01 11:26:25 +020012 expect req.bodylen == 0
13 expect req.body == ""
Willy Tarreau7b8d2032018-12-13 19:35:29 +010014 txresp \
15 -status 200 \
16 -body "response 1"
17
18 rxreq
Christopher Fauletf7b941c2019-04-01 11:26:25 +020019 expect req.bodylen == 0
20 expect req.body == ""
Willy Tarreau7b8d2032018-12-13 19:35:29 +010021 txresp \
22 -status 200 \
23 -body "response 2"
24
25 rxreq
Christopher Fauletf7b941c2019-04-01 11:26:25 +020026 expect req.bodylen == 38
27 expect req.body == "this must be delivered, like it or not"
Willy Tarreau7b8d2032018-12-13 19:35:29 +010028 txresp \
29 -status 200 \
30 -body "response 3"
31
32 rxreq
Christopher Fauletf7b941c2019-04-01 11:26:25 +020033 expect req.bodylen == 0
34 expect req.body == ""
Willy Tarreau7b8d2032018-12-13 19:35:29 +010035 txresp \
36 -status 200 \
37 -body "response 4"
Christopher Fauletf7b941c2019-04-01 11:26:25 +020038
39 accept
40
41 ##
42 ## Handle HEAD requests
43 ##
44 rxreq
45 expect req.bodylen == 0
46 expect req.body == ""
47 txresp \
48 -status 200 \
49 -body "response 1"
50
51 accept
52
53 rxreq
54 expect req.bodylen == 0
55 expect req.body == ""
56 txresp \
57 -status 200 \
58 -body "response 2"
59
60 accept
61
62 rxreq
63 expect req.bodylen == 38
64 expect req.body == "this must be delivered, like it or not"
65 txresp \
66 -status 200 \
67 -body "response 3"
68
69 accept
70
71 rxreq
72 expect req.bodylen == 0
73 expect req.body == ""
74 txresp \
75 -status 200 \
76 -body "response 4"
77
78 accept
79
80 ##
81 ## Handle POST requests
82 ##
83 # POST request without body
84 rxreq
85 expect req.bodylen == 0
86 expect req.body == ""
87 txresp \
88 -status 200 \
89 -body "response 1"
90
91 # POST request without body
92 rxreq
93 expect req.bodylen == 0
94 expect req.body == ""
95 txresp \
96 -status 200 \
97 -body "response 2"
98
99 # POST request with a body
100 rxreq
101 expect req.bodylen == 12
102 expect req.body == "this is sent"
103 txresp \
104 -status 200 \
105 -body "response 3"
106
107 # POST request without body
108 rxreq
109 expect req.bodylen == 0
110 expect req.body == ""
111 txresp \
112 -status 200 \
113 -body "response 4"
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100114} -repeat 3 -start
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100115
116haproxy h1 -conf {
Willy Tarreaue1465c12021-05-09 14:41:41 +0200117 global
118 # WT: limit false-positives causing "HTTP header incomplete" due to
119 # idle server connections being randomly used and randomly expiring
120 # under us.
121 tune.idle-pool.shared off
122
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100123 defaults
124 mode http
Willy Tarreauf6739232021-11-18 17:46:22 +0100125 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
126 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
127 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100128
129 listen feh1
130 bind "fd@${feh1}"
131 #bind "fd@${feh2}" proto h2
132 server s1 ${s1_addr}:${s1_port}
133} -start
134
135# GET requests
136client c1h1 -connect ${h1_feh1_sock} {
137 # first request is valid
138 txreq \
139 -req "GET" \
140 -url "/test1.html"
141 rxresp
142 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200143 expect resp.body == "response 1"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100144
145 # second request is valid and advertises C-L:0
146 txreq \
147 -req "GET" \
148 -url "/test2.html" \
149 -hdr "content-length: 0"
150 rxresp
151 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200152 expect resp.body == "response 2"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100153
154 # third request sends a body with a GET
155 txreq \
156 -req "GET" \
157 -url "/test3.html" \
158 -body "this must be delivered, like it or not"
159 rxresp
160 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200161 expect resp.body == "response 3"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100162
163 # fourth request is valid and advertises C-L:0, and close, and is
164 # followed by a string "this is not sent\r\n\r\n" which must be
165 # dropped.
166 txreq \
167 -req "GET" \
168 -url "/test4.html" \
169 -hdr "content-length: 0" \
170 -hdr "connection: close"
171 # "this is not sent"
172 sendhex "74787973207973206E6F742073656E740D0A0D0A"
173 rxresp
174 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200175 expect resp.body == "response 4"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100176
177 # the connection is expected to be closed and no more response must
178 # arrive here.
179 expect_close
180} -run
181
182# HEAD requests
183# Note: for now they fail with varnishtest, which expects the amount of
184# data advertised in the content-length response.
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100185client c2h1 -connect ${h1_feh1_sock} {
186 # first request is valid
187 txreq \
188 -req "HEAD" \
189 -url "/test11.html"
190 rxresp
191 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200192 expect resp.body == ""
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100193
194 # second request is valid and advertises C-L:0
195 txreq \
196 -req "HEAD" \
197 -url "/test12.html" \
198 -hdr "content-length: 0"
199 rxresp
200 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200201 expect resp.body == ""
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100202
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200203 # third request sends a body with a HEAD
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100204 txreq \
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200205 -req "HEAD" \
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100206 -url "/test13.html" \
207 -body "this must be delivered, like it or not"
208 rxresp
209 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200210 expect resp.body == ""
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100211
212 # fourth request is valid and advertises C-L:0, and close, and is
213 # followed by a string "this is not sent\r\n\r\n" which must be
214 # dropped.
215 txreq \
216 -req "HEAD" \
217 -url "/test14.html" \
218 -hdr "content-length: 0" \
219 -hdr "connection: close"
220 # "this is not sent"
221 sendhex "74787973207973206E6F742073656E740D0A0D0A"
222 rxresp
223 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200224 expect resp.body == ""
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100225
226 # the connection is expected to be closed and no more response must
227 # arrive here.
228 expect_close
229} -run
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100230
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200231client c3h1 -connect ${h1_feh1_sock} {
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100232 # first request is valid
233 txreq \
234 -req "POST" \
235 -url "/test21.html"
236 rxresp
237 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200238 expect resp.body == "response 1"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100239
240 # second request is valid and advertises C-L:0
241 txreq \
242 -req "POST" \
243 -url "/test22.html" \
244 -hdr "content-length: 0"
245 rxresp
246 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200247 expect resp.body == "response 2"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100248
Ilya Shipitsin47d17182020-06-21 21:42:57 +0500249 # third request is valid and advertises (and sends) some contents
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100250 txreq \
251 -req "POST" \
252 -url "/test23.html" \
253 -body "this is sent"
254 rxresp
255 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200256 expect resp.body == "response 3"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100257
258 # fourth request is valid and advertises C-L:0, and close, and is
259 # followed by a string "this is not sent\r\n\r\n" which must be
260 # dropped.
261 txreq \
262 -req "POST" \
263 -url "/test24.html" \
264 -hdr "content-length: 0" \
265 -hdr "connection: close"
266 # "this is not sent"
267 sendhex "74787973207973206E6F742073656E740D0A0D0A"
268 rxresp
269 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200270 expect resp.body == "response 4"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100271
272 # the connection is expected to be closed and no more response must
273 # arrive here.
274 expect_close
275} -run