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 | #REQUIRE_VERSION=1.6 |
| 3 | |
| 4 | # Run it with HAPROXY_PROGRAM=$PWD/haproxy varnishtest -l -k -t 1 "$1" |
| 5 | |
| 6 | feature ignore_unknown_macro |
| 7 | |
| 8 | server s1 { |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 9 | ## |
| 10 | ## Handle GET requests |
| 11 | ## |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 12 | rxreq |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 13 | expect req.bodylen == 0 |
| 14 | expect req.body == "" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 15 | txresp \ |
| 16 | -status 200 \ |
| 17 | -body "response 1" |
| 18 | |
| 19 | rxreq |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 20 | expect req.bodylen == 0 |
| 21 | expect req.body == "" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 22 | txresp \ |
| 23 | -status 200 \ |
| 24 | -body "response 2" |
| 25 | |
| 26 | rxreq |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 27 | expect req.bodylen == 38 |
| 28 | expect req.body == "this must be delivered, like it or not" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 29 | txresp \ |
| 30 | -status 200 \ |
| 31 | -body "response 3" |
| 32 | |
| 33 | rxreq |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 34 | expect req.bodylen == 0 |
| 35 | expect req.body == "" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 36 | txresp \ |
| 37 | -status 200 \ |
| 38 | -body "response 4" |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 39 | |
| 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écaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 115 | } -repeat 3 -start |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 116 | |
| 117 | haproxy h1 -conf { |
Willy Tarreau | e1465c1 | 2021-05-09 14:41:41 +0200 | [diff] [blame] | 118 | 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 Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 124 | defaults |
| 125 | mode http |
Christopher Faulet | 8f16148 | 2018-12-19 11:49:39 +0100 | [diff] [blame] | 126 | ${no-htx} option http-use-htx |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 127 | 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 |
| 138 | client 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 145 | expect resp.body == "response 1" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 146 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 154 | expect resp.body == "response 2" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 155 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 163 | expect resp.body == "response 3" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 164 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 177 | expect resp.body == "response 4" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 178 | |
| 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écaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 187 | client 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 194 | expect resp.body == "" |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 195 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 203 | expect resp.body == "" |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 204 | |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 205 | # third request sends a body with a HEAD |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 206 | txreq \ |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 207 | -req "HEAD" \ |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 208 | -url "/test13.html" \ |
| 209 | -body "this must be delivered, like it or not" |
| 210 | rxresp |
| 211 | expect resp.status == 200 |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 212 | expect resp.body == "" |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 213 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 226 | expect resp.body == "" |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 227 | |
| 228 | # the connection is expected to be closed and no more response must |
| 229 | # arrive here. |
| 230 | expect_close |
| 231 | } -run |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 232 | |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 233 | client c3h1 -connect ${h1_feh1_sock} { |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 234 | # first request is valid |
| 235 | txreq \ |
| 236 | -req "POST" \ |
| 237 | -url "/test21.html" |
| 238 | rxresp |
| 239 | expect resp.status == 200 |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 240 | expect resp.body == "response 1" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 241 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 249 | expect resp.body == "response 2" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 250 | |
Ilya Shipitsin | 47d1718 | 2020-06-21 21:42:57 +0500 | [diff] [blame] | 251 | # third request is valid and advertises (and sends) some contents |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 252 | txreq \ |
| 253 | -req "POST" \ |
| 254 | -url "/test23.html" \ |
| 255 | -body "this is sent" |
| 256 | rxresp |
| 257 | expect resp.status == 200 |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 258 | expect resp.body == "response 3" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 259 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 272 | expect resp.body == "response 4" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 273 | |
| 274 | # the connection is expected to be closed and no more response must |
| 275 | # arrive here. |
| 276 | expect_close |
| 277 | } -run |