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 { |
| 118 | defaults |
| 119 | mode http |
Christopher Faulet | 8f16148 | 2018-12-19 11:49:39 +0100 | [diff] [blame] | 120 | ${no-htx} option http-use-htx |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 121 | 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 |
| 132 | client 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 139 | expect resp.body == "response 1" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 140 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 148 | expect resp.body == "response 2" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 149 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 157 | expect resp.body == "response 3" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 158 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 171 | expect resp.body == "response 4" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 172 | |
| 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écaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 181 | client 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 188 | expect resp.body == "" |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 189 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 197 | expect resp.body == "" |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 198 | |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 199 | # third request sends a body with a HEAD |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 200 | txreq \ |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 201 | -req "HEAD" \ |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 202 | -url "/test13.html" \ |
| 203 | -body "this must be delivered, like it or not" |
| 204 | rxresp |
| 205 | expect resp.status == 200 |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 206 | expect resp.body == "" |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 207 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 220 | expect resp.body == "" |
Frédéric Lécaille | b5c71d7 | 2019-03-26 11:06:29 +0100 | [diff] [blame] | 221 | |
| 222 | # the connection is expected to be closed and no more response must |
| 223 | # arrive here. |
| 224 | expect_close |
| 225 | } -run |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 226 | |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 227 | client c3h1 -connect ${h1_feh1_sock} { |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 228 | # first request is valid |
| 229 | txreq \ |
| 230 | -req "POST" \ |
| 231 | -url "/test21.html" |
| 232 | rxresp |
| 233 | expect resp.status == 200 |
Christopher Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 234 | expect resp.body == "response 1" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 235 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 243 | expect resp.body == "response 2" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 244 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 252 | expect resp.body == "response 3" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 253 | |
| 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 Faulet | f7b941c | 2019-04-01 11:26:25 +0200 | [diff] [blame] | 266 | expect resp.body == "response 4" |
Willy Tarreau | 7b8d203 | 2018-12-13 19:35:29 +0100 | [diff] [blame] | 267 | |
| 268 | # the connection is expected to be closed and no more response must |
| 269 | # arrive here. |
| 270 | expect_close |
| 271 | } -run |