blob: 7694014c2a38451a942a218323e055e3676e259b [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 {
118 defaults
119 mode http
Christopher Faulet8f161482018-12-19 11:49:39 +0100120 ${no-htx} option http-use-htx
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100121 timeout connect 1s
122 timeout client 1s
123 timeout server 1s
124
125 listen feh1
126 bind "fd@${feh1}"
127 #bind "fd@${feh2}" proto h2
128 server s1 ${s1_addr}:${s1_port}
129} -start
130
131# GET requests
132client c1h1 -connect ${h1_feh1_sock} {
133 # first request is valid
134 txreq \
135 -req "GET" \
136 -url "/test1.html"
137 rxresp
138 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200139 expect resp.body == "response 1"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100140
141 # second request is valid and advertises C-L:0
142 txreq \
143 -req "GET" \
144 -url "/test2.html" \
145 -hdr "content-length: 0"
146 rxresp
147 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200148 expect resp.body == "response 2"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100149
150 # third request sends a body with a GET
151 txreq \
152 -req "GET" \
153 -url "/test3.html" \
154 -body "this must be delivered, like it or not"
155 rxresp
156 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200157 expect resp.body == "response 3"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100158
159 # fourth request is valid and advertises C-L:0, and close, and is
160 # followed by a string "this is not sent\r\n\r\n" which must be
161 # dropped.
162 txreq \
163 -req "GET" \
164 -url "/test4.html" \
165 -hdr "content-length: 0" \
166 -hdr "connection: close"
167 # "this is not sent"
168 sendhex "74787973207973206E6F742073656E740D0A0D0A"
169 rxresp
170 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200171 expect resp.body == "response 4"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100172
173 # the connection is expected to be closed and no more response must
174 # arrive here.
175 expect_close
176} -run
177
178# HEAD requests
179# Note: for now they fail with varnishtest, which expects the amount of
180# data advertised in the content-length response.
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100181client c2h1 -connect ${h1_feh1_sock} {
182 # first request is valid
183 txreq \
184 -req "HEAD" \
185 -url "/test11.html"
186 rxresp
187 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200188 expect resp.body == ""
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100189
190 # second request is valid and advertises C-L:0
191 txreq \
192 -req "HEAD" \
193 -url "/test12.html" \
194 -hdr "content-length: 0"
195 rxresp
196 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200197 expect resp.body == ""
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100198
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200199 # third request sends a body with a HEAD
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100200 txreq \
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200201 -req "HEAD" \
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100202 -url "/test13.html" \
203 -body "this must be delivered, like it or not"
204 rxresp
205 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200206 expect resp.body == ""
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100207
208 # fourth request is valid and advertises C-L:0, and close, and is
209 # followed by a string "this is not sent\r\n\r\n" which must be
210 # dropped.
211 txreq \
212 -req "HEAD" \
213 -url "/test14.html" \
214 -hdr "content-length: 0" \
215 -hdr "connection: close"
216 # "this is not sent"
217 sendhex "74787973207973206E6F742073656E740D0A0D0A"
218 rxresp
219 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200220 expect resp.body == ""
Frédéric Lécailleb5c71d72019-03-26 11:06:29 +0100221
222 # the connection is expected to be closed and no more response must
223 # arrive here.
224 expect_close
225} -run
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100226
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200227client c3h1 -connect ${h1_feh1_sock} {
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100228 # first request is valid
229 txreq \
230 -req "POST" \
231 -url "/test21.html"
232 rxresp
233 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200234 expect resp.body == "response 1"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100235
236 # second request is valid and advertises C-L:0
237 txreq \
238 -req "POST" \
239 -url "/test22.html" \
240 -hdr "content-length: 0"
241 rxresp
242 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200243 expect resp.body == "response 2"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100244
245 # third request is valid and advertises (and sends) somme contents
246 txreq \
247 -req "POST" \
248 -url "/test23.html" \
249 -body "this is sent"
250 rxresp
251 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200252 expect resp.body == "response 3"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100253
254 # fourth request is valid and advertises C-L:0, and close, and is
255 # followed by a string "this is not sent\r\n\r\n" which must be
256 # dropped.
257 txreq \
258 -req "POST" \
259 -url "/test24.html" \
260 -hdr "content-length: 0" \
261 -hdr "connection: close"
262 # "this is not sent"
263 sendhex "74787973207973206E6F742073656E740D0A0D0A"
264 rxresp
265 expect resp.status == 200
Christopher Fauletf7b941c2019-04-01 11:26:25 +0200266 expect resp.body == "response 4"
Willy Tarreau7b8d2032018-12-13 19:35:29 +0100267
268 # the connection is expected to be closed and no more response must
269 # arrive here.
270 expect_close
271} -run