Remi Tricot-Le Breton | 14df1e1 | 2020-12-23 18:13:51 +0100 | [diff] [blame] | 1 | varnishtest "Check the Accept-Encoding processing implemented in the Vary mechanism" |
| 2 | |
| 3 | #REQUIRE_VERSION=2.4 |
| 4 | |
| 5 | feature ignore_unknown_macro |
| 6 | |
| 7 | server s1 { |
| 8 | # Response varying on "accept-encoding" with a gzip content-encoding |
| 9 | rxreq |
| 10 | expect req.url == "/accept-encoding" |
| 11 | txresp -hdr "Content-Encoding: gzip" \ |
| 12 | -hdr "Vary: accept-encoding" \ |
| 13 | -hdr "Cache-Control: max-age=5" \ |
| 14 | -bodylen 45 |
| 15 | |
| 16 | # Response varying on "accept-encoding" with a deflate content-encoding |
| 17 | rxreq |
| 18 | expect req.url == "/accept-encoding" |
| 19 | txresp -hdr "Content-Encoding: deflate" \ |
| 20 | -hdr "Vary: accept-encoding" \ |
| 21 | -hdr "Cache-Control: max-age=5" \ |
| 22 | -bodylen 55 |
| 23 | |
| 24 | |
| 25 | # Response varying on "accept-encoding" with no content-encoding (identity) |
| 26 | rxreq |
| 27 | expect req.url == "/accept-encoding-identity" |
| 28 | txresp -hdr "Vary: accept-encoding" \ |
| 29 | -hdr "Cache-Control: max-age=5" \ |
| 30 | -bodylen 65 |
| 31 | |
| 32 | # Response varying on "accept-encoding" with refused identity encoding |
| 33 | rxreq |
| 34 | expect req.url == "/accept-encoding-identity" |
| 35 | txresp -hdr "Vary: accept-encoding" \ |
| 36 | -hdr "Cache-Control: max-age=5" \ |
| 37 | -hdr "Content-Encoding: deflate" \ |
| 38 | -bodylen 75 |
| 39 | |
| 40 | |
| 41 | rxreq |
| 42 | expect req.url == "/accept-encoding-star" |
| 43 | txresp -hdr "Vary: accept-encoding" \ |
| 44 | -hdr "Cache-Control: max-age=5" \ |
| 45 | -hdr "Content-Encoding: br" \ |
| 46 | -bodylen 89 |
| 47 | |
| 48 | rxreq |
| 49 | expect req.url == "/accept-encoding-star" |
| 50 | txresp -hdr "Vary: accept-encoding" \ |
| 51 | -hdr "Cache-Control: max-age=5" \ |
| 52 | -hdr "Content-Encoding: deflate" \ |
| 53 | -bodylen 99 |
| 54 | |
| 55 | |
| 56 | rxreq |
| 57 | expect req.url == "/multiple-content-encoding" |
| 58 | txresp -hdr "Vary: accept-encoding" \ |
| 59 | -hdr "Cache-Control: max-age=5" \ |
| 60 | -hdr "Content-Encoding: deflate, gzip" \ |
| 61 | -bodylen 109 |
| 62 | |
| 63 | rxreq |
| 64 | expect req.url == "/unknown-content-encoding" |
| 65 | txresp -hdr "Vary: accept-encoding" \ |
| 66 | -hdr "Cache-Control: max-age=5" \ |
| 67 | -hdr "Content-Encoding: unknown_encoding" \ |
| 68 | -bodylen 119 |
| 69 | |
| 70 | rxreq |
| 71 | expect req.url == "/unknown-content-encoding" |
| 72 | txresp -hdr "Vary: accept-encoding" \ |
| 73 | -hdr "Cache-Control: max-age=5" \ |
| 74 | -hdr "Content-Encoding: unknown_encoding" \ |
| 75 | -bodylen 119 |
Tim Duesterhus | dc38bc4 | 2020-12-29 12:43:53 +0100 | [diff] [blame] | 76 | |
| 77 | |
| 78 | rxreq |
| 79 | expect req.url == "/hash-collision" |
| 80 | txresp -hdr "Vary: accept-encoding" \ |
| 81 | -hdr "Cache-Control: max-age=5" \ |
| 82 | -hdr "Content-Encoding: br" \ |
| 83 | -bodylen 129 |
| 84 | |
| 85 | rxreq |
| 86 | expect req.url == "/hash-collision" |
| 87 | txresp -hdr "Vary: accept-encoding" \ |
| 88 | -hdr "Cache-Control: max-age=5" \ |
| 89 | -hdr "Content-Encoding: gzip" \ |
| 90 | -bodylen 139 |
Remi Tricot-Le Breton | 14df1e1 | 2020-12-23 18:13:51 +0100 | [diff] [blame] | 91 | } -start |
| 92 | |
| 93 | |
| 94 | haproxy h1 -conf { |
Willy Tarreau | e1465c1 | 2021-05-09 14:41:41 +0200 | [diff] [blame] | 95 | global |
| 96 | # WT: limit false-positives causing "HTTP header incomplete" due to |
| 97 | # idle server connections being randomly used and randomly expiring |
| 98 | # under us. |
| 99 | tune.idle-pool.shared off |
| 100 | |
Remi Tricot-Le Breton | 14df1e1 | 2020-12-23 18:13:51 +0100 | [diff] [blame] | 101 | defaults |
| 102 | mode http |
Willy Tarreau | f673923 | 2021-11-18 17:46:22 +0100 | [diff] [blame] | 103 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 104 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 105 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
Remi Tricot-Le Breton | 14df1e1 | 2020-12-23 18:13:51 +0100 | [diff] [blame] | 106 | |
| 107 | frontend fe |
| 108 | bind "fd@${fe}" |
| 109 | default_backend test |
| 110 | |
| 111 | backend test |
| 112 | http-request cache-use my_cache |
| 113 | server www ${s1_addr}:${s1_port} |
| 114 | http-response cache-store my_cache |
| 115 | http-response set-header X-Cache-Hit %[res.cache_hit] |
| 116 | |
| 117 | cache my_cache |
| 118 | total-max-size 3 |
| 119 | max-age 20 |
| 120 | max-object-size 3072 |
Remi Tricot-Le Breton | e6cc5b5 | 2020-12-23 18:13:53 +0100 | [diff] [blame] | 121 | process-vary on |
Remi Tricot-Le Breton | 14df1e1 | 2020-12-23 18:13:51 +0100 | [diff] [blame] | 122 | } -start |
| 123 | |
| 124 | |
| 125 | client c1 -connect ${h1_fe_sock} { |
| 126 | # |
| 127 | # Accept-Encoding Vary |
| 128 | # |
| 129 | |
| 130 | # First request |
| 131 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: gzip" |
| 132 | rxresp |
| 133 | expect resp.status == 200 |
| 134 | expect resp.http.content-encoding == "gzip" |
| 135 | expect resp.bodylen == 45 |
| 136 | |
| 137 | # Regular case |
| 138 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: gzip" |
| 139 | rxresp |
| 140 | expect resp.status == 200 |
| 141 | expect resp.http.content-encoding == "gzip" |
| 142 | expect resp.bodylen == 45 |
| 143 | expect resp.http.X-Cache-Hit == 1 |
| 144 | |
| 145 | # Regular case with upper case encoding |
| 146 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: GZIP" |
| 147 | rxresp |
| 148 | expect resp.status == 200 |
| 149 | expect resp.http.content-encoding == "gzip" |
| 150 | expect resp.bodylen == 45 |
| 151 | expect resp.http.X-Cache-Hit == 1 |
| 152 | |
| 153 | # Multiple accepted encodings (all standard) |
| 154 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: deflate,gzip" |
| 155 | rxresp |
| 156 | expect resp.status == 200 |
| 157 | expect resp.http.content-encoding == "gzip" |
| 158 | expect resp.bodylen == 45 |
| 159 | expect resp.http.X-Cache-Hit == 1 |
| 160 | |
| 161 | # Multiple accept-encoding headers + non-standard accepted encodings |
| 162 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_encoding,second_encoding" -hdr "Accept-Encoding: gzip" |
| 163 | rxresp |
| 164 | expect resp.status == 200 |
| 165 | expect resp.http.content-encoding == "gzip" |
| 166 | expect resp.bodylen == 45 |
| 167 | expect resp.http.X-Cache-Hit == 1 |
| 168 | |
| 169 | # Regular case with positive weight |
| 170 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: gzip;q=0.8" |
| 171 | rxresp |
| 172 | expect resp.status == 200 |
| 173 | expect resp.http.content-encoding == "gzip" |
| 174 | expect resp.bodylen == 45 |
| 175 | expect resp.http.X-Cache-Hit == 1 |
| 176 | |
| 177 | # Regular case with positive weight and extra whitespaces |
| 178 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: gzip ; q=0.8" |
| 179 | rxresp |
| 180 | expect resp.status == 200 |
| 181 | expect resp.http.content-encoding == "gzip" |
| 182 | expect resp.bodylen == 45 |
| 183 | expect resp.http.X-Cache-Hit == 1 |
| 184 | |
| 185 | # Regular case with null weight |
| 186 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: deflate;q=0.8, gzip;q=0" |
| 187 | rxresp |
| 188 | expect resp.status == 200 |
| 189 | expect resp.http.content-encoding == "deflate" |
| 190 | expect resp.bodylen == 55 |
| 191 | expect resp.http.X-Cache-Hit == 0 |
| 192 | |
| 193 | |
| 194 | # |
| 195 | # Identity tests |
| 196 | # |
| 197 | txreq -url "/accept-encoding-identity" |
| 198 | rxresp |
| 199 | expect resp.status == 200 |
| 200 | expect resp.http.content-encoding == "<undef>" |
| 201 | expect resp.bodylen == 65 |
| 202 | expect resp.http.X-Cache-Hit == 0 |
| 203 | |
| 204 | # Regular case |
| 205 | txreq -url "/accept-encoding-identity" |
| 206 | rxresp |
| 207 | expect resp.status == 200 |
| 208 | expect resp.http.content-encoding == "<undef>" |
| 209 | expect resp.bodylen == 65 |
| 210 | expect resp.http.X-Cache-Hit == 1 |
| 211 | |
| 212 | # Identity is allowed by default even if another encoding is specified |
| 213 | txreq -url "/accept-encoding-identity" -hdr "Accept-Encoding: gzip" |
| 214 | rxresp |
| 215 | expect resp.status == 200 |
| 216 | expect resp.http.content-encoding == "<undef>" |
| 217 | expect resp.bodylen == 65 |
| 218 | expect resp.http.X-Cache-Hit == 1 |
| 219 | |
| 220 | # Refused identity encoding (explicit null weight) |
| 221 | txreq -url "/accept-encoding-identity" -hdr "Accept-Encoding: deflate, identity;q=0" |
| 222 | rxresp |
| 223 | expect resp.status == 200 |
| 224 | expect resp.http.content-encoding == "deflate" |
| 225 | expect resp.bodylen == 75 |
| 226 | expect resp.http.X-Cache-Hit == 0 |
| 227 | |
| 228 | |
| 229 | # |
| 230 | # Star tests |
| 231 | # |
| 232 | txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: *" |
| 233 | rxresp |
| 234 | expect resp.status == 200 |
| 235 | expect resp.http.content-encoding == "br" |
| 236 | expect resp.bodylen == 89 |
| 237 | expect resp.http.X-Cache-Hit == 0 |
| 238 | |
| 239 | # Regular case |
| 240 | txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: *" |
| 241 | rxresp |
| 242 | expect resp.status == 200 |
| 243 | expect resp.http.content-encoding == "br" |
| 244 | expect resp.bodylen == 89 |
| 245 | expect resp.http.X-Cache-Hit == 1 |
| 246 | |
| 247 | # Reject some encodings |
| 248 | txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: gzip;q=0, deflate,*" |
| 249 | rxresp |
| 250 | expect resp.status == 200 |
| 251 | expect resp.http.content-encoding == "br" |
| 252 | expect resp.bodylen == 89 |
| 253 | expect resp.http.X-Cache-Hit == 1 |
| 254 | |
| 255 | # Weighted star |
| 256 | txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: gzip;q=0, deflate,*;q=0.1" |
| 257 | rxresp |
| 258 | expect resp.status == 200 |
| 259 | expect resp.http.content-encoding == "br" |
| 260 | expect resp.bodylen == 89 |
| 261 | expect resp.http.X-Cache-Hit == 1 |
| 262 | |
| 263 | # Rejected identity |
| 264 | txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: gzip;q=0, deflate,*;q=0.1,identity;q=0" |
| 265 | rxresp |
| 266 | expect resp.status == 200 |
| 267 | expect resp.http.content-encoding == "br" |
| 268 | expect resp.bodylen == 89 |
| 269 | expect resp.http.X-Cache-Hit == 1 |
| 270 | |
| 271 | # Rejected star and "br" not accepted |
| 272 | txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: gzip;q=0, deflate,*;q=0" |
| 273 | rxresp |
| 274 | expect resp.status == 200 |
| 275 | expect resp.http.content-encoding == "deflate" |
| 276 | expect resp.bodylen == 99 |
| 277 | expect resp.http.X-Cache-Hit == 0 |
| 278 | |
| 279 | |
| 280 | # |
| 281 | # Multiple content-encodings |
| 282 | # |
| 283 | txreq -url "/multiple-content-encoding" -hdr "Accept-Encoding: gzip;q=0.8, deflate" |
| 284 | rxresp |
| 285 | expect resp.status == 200 |
| 286 | expect resp.http.content-encoding == "deflate, gzip" |
| 287 | expect resp.bodylen == 109 |
| 288 | expect resp.http.X-Cache-Hit == 0 |
| 289 | |
| 290 | txreq -url "/multiple-content-encoding" -hdr "Accept-Encoding: deflate,gzip;q=0.7" |
| 291 | rxresp |
| 292 | expect resp.status == 200 |
| 293 | expect resp.http.content-encoding == "deflate, gzip" |
| 294 | expect resp.bodylen == 109 |
| 295 | expect resp.http.X-Cache-Hit == 1 |
| 296 | |
| 297 | |
| 298 | # |
| 299 | # Unknown content-encoding |
Remi Tricot-Le Breton | 6ca8916 | 2021-01-07 14:50:51 +0100 | [diff] [blame] | 300 | # The response should not be cached since it has an unknown content encoding |
Remi Tricot-Le Breton | 14df1e1 | 2020-12-23 18:13:51 +0100 | [diff] [blame] | 301 | # |
| 302 | txreq -url "/unknown-content-encoding" -hdr "Accept-Encoding: gzip;q=0.8, deflate, first_encoding" |
| 303 | rxresp |
| 304 | expect resp.status == 200 |
| 305 | expect resp.http.content-encoding == "unknown_encoding" |
| 306 | expect resp.bodylen == 119 |
| 307 | expect resp.http.X-Cache-Hit == 0 |
| 308 | |
| 309 | txreq -url "/unknown-content-encoding" -hdr "Accept-Encoding: deflate,gzip;q=0.8, first_encoding" |
| 310 | rxresp |
| 311 | expect resp.status == 200 |
| 312 | expect resp.http.content-encoding == "unknown_encoding" |
| 313 | expect resp.bodylen == 119 |
Remi Tricot-Le Breton | 14df1e1 | 2020-12-23 18:13:51 +0100 | [diff] [blame] | 314 | expect resp.http.X-Cache-Hit == 0 |
| 315 | |
Tim Duesterhus | dc38bc4 | 2020-12-29 12:43:53 +0100 | [diff] [blame] | 316 | # |
| 317 | # Hash collision (https://github.com/haproxy/haproxy/issues/988) |
| 318 | # |
| 319 | # crc32(gzip) ^ crc32(br) ^ crc32(xxx) ^ crc32(jdcqiab) == crc32(gzip) |
| 320 | txreq -url "/hash-collision" -hdr "Accept-Encoding: br,gzip,xxx,jdcqiab" |
| 321 | rxresp |
| 322 | expect resp.status == 200 |
| 323 | expect resp.http.content-encoding == "br" |
| 324 | expect resp.bodylen == 129 |
| 325 | expect resp.http.X-Cache-Hit == 0 |
| 326 | |
| 327 | txreq -url "/hash-collision" -hdr "Accept-Encoding: gzip" |
| 328 | rxresp |
| 329 | expect resp.status == 200 |
| 330 | expect resp.http.content-encoding == "gzip" |
| 331 | expect resp.bodylen == 139 |
| 332 | expect resp.http.X-Cache-Hit == 0 |
Remi Tricot-Le Breton | 14df1e1 | 2020-12-23 18:13:51 +0100 | [diff] [blame] | 333 | } -run |