Christopher Faulet | 8f16148 | 2018-12-19 11:49:39 +0100 | [diff] [blame] | 1 | varnishtest "HTTP request tests: H1 to H1 (HTX mode supported only for HAProxy >= 1.9)" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 2 | |
| 3 | # Run it with HAPROXY_PROGRAM=$PWD/haproxy varnishtest -l -k -t 1 "$1" |
| 4 | |
| 5 | feature ignore_unknown_macro |
| 6 | |
| 7 | server s1 { |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 8 | ## |
| 9 | ## Handle GET requests |
| 10 | ## |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 11 | rxreq |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 12 | expect req.bodylen == 0 |
| 13 | expect req.body == "" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 14 | txresp \ |
| 15 | -status 200 \ |
| 16 | -body "response 1" |
| 17 | |
| 18 | rxreq |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 19 | expect req.bodylen == 0 |
| 20 | expect req.body == "" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 21 | txresp \ |
| 22 | -status 200 \ |
| 23 | -body "response 2" |
| 24 | |
| 25 | rxreq |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 26 | expect req.bodylen == 38 |
| 27 | expect req.body == "this must be delivered, like it or not" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 28 | txresp \ |
| 29 | -status 200 \ |
| 30 | -body "response 3" |
| 31 | |
| 32 | rxreq |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 33 | expect req.bodylen == 0 |
| 34 | expect req.body == "" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 35 | txresp \ |
| 36 | -status 200 \ |
| 37 | -body "response 4" |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 38 | |
| 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écaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 114 | } -repeat 3 -start |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 115 | |
| 116 | haproxy h1 -conf { |
Willy Tarreau | e1465c1 | 2021-05-09 14:41:41 +0200 | [diff] [blame] | 117 | 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 Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 123 | defaults |
| 124 | mode http |
Willy Tarreau | f673923 | 2021-11-18 17:46:22 +0100 | [diff] [blame] | 125 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 126 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 127 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 128 | |
| 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 |
| 136 | client 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 143 | expect resp.body == "response 1" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 144 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 152 | expect resp.body == "response 2" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 153 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 161 | expect resp.body == "response 3" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 162 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 175 | expect resp.body == "response 4" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 176 | |
| 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écaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 185 | client 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 192 | expect resp.body == "" |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 193 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 201 | expect resp.body == "" |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 202 | |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 203 | # third request sends a body with a HEAD |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 204 | txreq \ |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 205 | -req "HEAD" \ |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 206 | -url "/test13.html" \ |
| 207 | -body "this must be delivered, like it or not" |
| 208 | rxresp |
| 209 | expect resp.status == 200 |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 210 | expect resp.body == "" |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 211 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 224 | expect resp.body == "" |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 225 | |
| 226 | # the connection is expected to be closed and no more response must |
| 227 | # arrive here. |
| 228 | expect_close |
| 229 | } -run |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 230 | |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 231 | client c3h1 -connect ${h1_feh1_sock} { |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 232 | # first request is valid |
| 233 | txreq \ |
| 234 | -req "POST" \ |
| 235 | -url "/test21.html" |
| 236 | rxresp |
| 237 | expect resp.status == 200 |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 238 | expect resp.body == "response 1" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 239 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 247 | expect resp.body == "response 2" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 248 | |
Ilya Shipitsin | 47d1718 | 2020-06-21 21:42:57 +0500 | [diff] [blame] | 249 | # third request is valid and advertises (and sends) some contents |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 250 | txreq \ |
| 251 | -req "POST" \ |
| 252 | -url "/test23.html" \ |
| 253 | -body "this is sent" |
| 254 | rxresp |
| 255 | expect resp.status == 200 |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 256 | expect resp.body == "response 3" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 257 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 270 | expect resp.body == "response 4" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 271 | |
| 272 | # the connection is expected to be closed and no more response must |
| 273 | # arrive here. |
| 274 | expect_close |
| 275 | } -run |