blob: c7d00858ea45add32945fd5418420a20548af9cd [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#REQUIRE_VERSION=1.6
3
4# Run it with HAPROXY_PROGRAM=$PWD/haproxy varnishtest -l -k -t 1 "$1"
5
6feature ignore_unknown_macro
7
8server s1 {
Christopher Fauletf7b941c2019-04-01 11:26:25 +02009 ##
10 ## Handle GET requests
11 ##
Willy Tarreau7b8d2032018-12-13 19:35:29 +010012 rxreq
Christopher Fauletf7b941c2019-04-01 11:26:25 +020013 expect req.bodylen == 0
14 expect req.body == ""
Willy Tarreau7b8d2032018-12-13 19:35:29 +010015 txresp \
16 -status 200 \
17 -body "response 1"
18
19 rxreq
Christopher Fauletf7b941c2019-04-01 11:26:25 +020020 expect req.bodylen == 0
21 expect req.body == ""
Willy Tarreau7b8d2032018-12-13 19:35:29 +010022 txresp \
23 -status 200 \
24 -body "response 2"
25
26 rxreq
Christopher Fauletf7b941c2019-04-01 11:26:25 +020027 expect req.bodylen == 38
28 expect req.body == "this must be delivered, like it or not"
Willy Tarreau7b8d2032018-12-13 19:35:29 +010029 txresp \
30 -status 200 \
31 -body "response 3"
32
33 rxreq
Christopher Fauletf7b941c2019-04-01 11:26:25 +020034 expect req.bodylen == 0
35 expect req.body == ""
Willy Tarreau7b8d2032018-12-13 19:35:29 +010036 txresp \
37 -status 200 \
38 -body "response 4"
Christopher Fauletf7b941c2019-04-01 11:26:25 +020039
40 accept
41
42 ##
43 ## Handle HEAD requests
44 ##
45 rxreq
46 expect req.bodylen == 0
47 expect req.body == ""
48 txresp \
49 -status 200 \
50 -body "response 1"
51
52 accept
53
54 rxreq
55 expect req.bodylen == 0
56 expect req.body == ""
57 txresp \
58 -status 200 \
59 -body "response 2"
60
61 accept
62
63 rxreq
64 expect req.bodylen == 38
65 expect req.body == "this must be delivered, like it or not"
66 txresp \
67 -status 200 \
68 -body "response 3"
69
70 accept
71
72 rxreq
73 expect req.bodylen == 0
74 expect req.body == ""
75 txresp \
76 -status 200 \
77 -body "response 4"
78
79 accept
80
81 ##
82 ## Handle POST requests
83 ##
84 # POST request without body
85 rxreq
86 expect req.bodylen == 0
87 expect req.body == ""
88 txresp \
89 -status 200 \
90 -body "response 1"
91
92 # POST request without body
93 rxreq
94 expect req.bodylen == 0
95 expect req.body == ""
96 txresp \
97 -status 200 \
98 -body "response 2"
99
100 # POST request with a body
101 rxreq
102 expect req.bodylen == 12
103 expect req.body == "this is sent"
104 txresp \
105 -status 200 \
106 -body "response 3"
107
108 # POST request without body
109 rxreq
110 expect req.bodylen == 0
111 expect req.body == ""
112 txresp \
113 -status 200 \
114 -body "response 4"
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100115} -repeat 3 -start
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100116
117haproxy h1 -conf {
Willy Tarreaue1465c12021-05-09 14:41:41 +0200118 global
119 # WT: limit false-positives causing "HTTP header incomplete" due to
120 # idle server connections being randomly used and randomly expiring
121 # under us.
122 tune.idle-pool.shared off
123
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100124 defaults
125 mode http
Christopher Faulet8f161482018-12-19 11:49:39 +0100126 ${no-htx} option http-use-htx
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100127 timeout connect 1s
128 timeout client 1s
129 timeout server 1s
130
131 listen feh1
132 bind "fd@${feh1}"
133 #bind "fd@${feh2}" proto h2
134 server s1 ${s1_addr}:${s1_port}
135} -start
136
137# GET requests
138client c1h1 -connect ${h1_feh1_sock} {
139 # first request is valid
140 txreq \
141 -req "GET" \
142 -url "/test1.html"
143 rxresp
144 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200145 expect resp.body == "response 1"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100146
147 # second request is valid and advertises C-L:0
148 txreq \
149 -req "GET" \
150 -url "/test2.html" \
151 -hdr "content-length: 0"
152 rxresp
153 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200154 expect resp.body == "response 2"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100155
156 # third request sends a body with a GET
157 txreq \
158 -req "GET" \
159 -url "/test3.html" \
160 -body "this must be delivered, like it or not"
161 rxresp
162 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200163 expect resp.body == "response 3"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100164
165 # fourth request is valid and advertises C-L:0, and close, and is
166 # followed by a string "this is not sent\r\n\r\n" which must be
167 # dropped.
168 txreq \
169 -req "GET" \
170 -url "/test4.html" \
171 -hdr "content-length: 0" \
172 -hdr "connection: close"
173 # "this is not sent"
174 sendhex "74787973207973206E6F742073656E740D0A0D0A"
175 rxresp
176 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200177 expect resp.body == "response 4"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100178
179 # the connection is expected to be closed and no more response must
180 # arrive here.
181 expect_close
182} -run
183
184# HEAD requests
185# Note: for now they fail with varnishtest, which expects the amount of
186# data advertised in the content-length response.
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100187client c2h1 -connect ${h1_feh1_sock} {
188 # first request is valid
189 txreq \
190 -req "HEAD" \
191 -url "/test11.html"
192 rxresp
193 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200194 expect resp.body == ""
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100195
196 # second request is valid and advertises C-L:0
197 txreq \
198 -req "HEAD" \
199 -url "/test12.html" \
200 -hdr "content-length: 0"
201 rxresp
202 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200203 expect resp.body == ""
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100204
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200205 # third request sends a body with a HEAD
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100206 txreq \
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200207 -req "HEAD" \
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100208 -url "/test13.html" \
209 -body "this must be delivered, like it or not"
210 rxresp
211 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200212 expect resp.body == ""
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100213
214 # fourth request is valid and advertises C-L:0, and close, and is
215 # followed by a string "this is not sent\r\n\r\n" which must be
216 # dropped.
217 txreq \
218 -req "HEAD" \
219 -url "/test14.html" \
220 -hdr "content-length: 0" \
221 -hdr "connection: close"
222 # "this is not sent"
223 sendhex "74787973207973206E6F742073656E740D0A0D0A"
224 rxresp
225 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200226 expect resp.body == ""
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100227
228 # the connection is expected to be closed and no more response must
229 # arrive here.
230 expect_close
231} -run
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100232
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200233client c3h1 -connect ${h1_feh1_sock} {
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100234 # first request is valid
235 txreq \
236 -req "POST" \
237 -url "/test21.html"
238 rxresp
239 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200240 expect resp.body == "response 1"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100241
242 # second request is valid and advertises C-L:0
243 txreq \
244 -req "POST" \
245 -url "/test22.html" \
246 -hdr "content-length: 0"
247 rxresp
248 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200249 expect resp.body == "response 2"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100250
Ilya Shipitsin47d17182020-06-21 21:42:57 +0500251 # third request is valid and advertises (and sends) some contents
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100252 txreq \
253 -req "POST" \
254 -url "/test23.html" \
255 -body "this is sent"
256 rxresp
257 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200258 expect resp.body == "response 3"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100259
260 # fourth request is valid and advertises C-L:0, and close, and is
261 # followed by a string "this is not sent\r\n\r\n" which must be
262 # dropped.
263 txreq \
264 -req "POST" \
265 -url "/test24.html" \
266 -hdr "content-length: 0" \
267 -hdr "connection: close"
268 # "this is not sent"
269 sendhex "74787973207973206E6F742073656E740D0A0D0A"
270 rxresp
271 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200272 expect resp.body == "response 4"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100273
274 # the connection is expected to be closed and no more response must
275 # arrive here.
276 expect_close
277} -run