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 |
| 103 | ${no-htx} option http-use-htx |
| 104 | timeout connect 1s |
| 105 | timeout client 1s |
| 106 | timeout server 1s |
| 107 | |
| 108 | frontend fe |
| 109 | bind "fd@${fe}" |
| 110 | default_backend test |
| 111 | |
| 112 | backend test |
| 113 | http-request cache-use my_cache |
| 114 | server www ${s1_addr}:${s1_port} |
| 115 | http-response cache-store my_cache |
| 116 | http-response set-header X-Cache-Hit %[res.cache_hit] |
| 117 | |
| 118 | cache my_cache |
| 119 | total-max-size 3 |
| 120 | max-age 20 |
| 121 | max-object-size 3072 |
Remi Tricot-Le Breton | e6cc5b5 | 2020-12-23 18:13:53 +0100 | [diff] [blame] | 122 | process-vary on |
Remi Tricot-Le Breton | 14df1e1 | 2020-12-23 18:13:51 +0100 | [diff] [blame] | 123 | } -start |
| 124 | |
| 125 | |
| 126 | client c1 -connect ${h1_fe_sock} { |
| 127 | # |
| 128 | # Accept-Encoding Vary |
| 129 | # |
| 130 | |
| 131 | # First request |
| 132 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: gzip" |
| 133 | rxresp |
| 134 | expect resp.status == 200 |
| 135 | expect resp.http.content-encoding == "gzip" |
| 136 | expect resp.bodylen == 45 |
| 137 | |
| 138 | # Regular case |
| 139 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: gzip" |
| 140 | rxresp |
| 141 | expect resp.status == 200 |
| 142 | expect resp.http.content-encoding == "gzip" |
| 143 | expect resp.bodylen == 45 |
| 144 | expect resp.http.X-Cache-Hit == 1 |
| 145 | |
| 146 | # Regular case with upper case encoding |
| 147 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: GZIP" |
| 148 | rxresp |
| 149 | expect resp.status == 200 |
| 150 | expect resp.http.content-encoding == "gzip" |
| 151 | expect resp.bodylen == 45 |
| 152 | expect resp.http.X-Cache-Hit == 1 |
| 153 | |
| 154 | # Multiple accepted encodings (all standard) |
| 155 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: deflate,gzip" |
| 156 | rxresp |
| 157 | expect resp.status == 200 |
| 158 | expect resp.http.content-encoding == "gzip" |
| 159 | expect resp.bodylen == 45 |
| 160 | expect resp.http.X-Cache-Hit == 1 |
| 161 | |
| 162 | # Multiple accept-encoding headers + non-standard accepted encodings |
| 163 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_encoding,second_encoding" -hdr "Accept-Encoding: gzip" |
| 164 | rxresp |
| 165 | expect resp.status == 200 |
| 166 | expect resp.http.content-encoding == "gzip" |
| 167 | expect resp.bodylen == 45 |
| 168 | expect resp.http.X-Cache-Hit == 1 |
| 169 | |
| 170 | # Regular case with positive weight |
| 171 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: gzip;q=0.8" |
| 172 | rxresp |
| 173 | expect resp.status == 200 |
| 174 | expect resp.http.content-encoding == "gzip" |
| 175 | expect resp.bodylen == 45 |
| 176 | expect resp.http.X-Cache-Hit == 1 |
| 177 | |
| 178 | # Regular case with positive weight and extra whitespaces |
| 179 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: gzip ; q=0.8" |
| 180 | rxresp |
| 181 | expect resp.status == 200 |
| 182 | expect resp.http.content-encoding == "gzip" |
| 183 | expect resp.bodylen == 45 |
| 184 | expect resp.http.X-Cache-Hit == 1 |
| 185 | |
| 186 | # Regular case with null weight |
| 187 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: deflate;q=0.8, gzip;q=0" |
| 188 | rxresp |
| 189 | expect resp.status == 200 |
| 190 | expect resp.http.content-encoding == "deflate" |
| 191 | expect resp.bodylen == 55 |
| 192 | expect resp.http.X-Cache-Hit == 0 |
| 193 | |
| 194 | |
| 195 | # |
| 196 | # Identity tests |
| 197 | # |
| 198 | txreq -url "/accept-encoding-identity" |
| 199 | rxresp |
| 200 | expect resp.status == 200 |
| 201 | expect resp.http.content-encoding == "<undef>" |
| 202 | expect resp.bodylen == 65 |
| 203 | expect resp.http.X-Cache-Hit == 0 |
| 204 | |
| 205 | # Regular case |
| 206 | txreq -url "/accept-encoding-identity" |
| 207 | rxresp |
| 208 | expect resp.status == 200 |
| 209 | expect resp.http.content-encoding == "<undef>" |
| 210 | expect resp.bodylen == 65 |
| 211 | expect resp.http.X-Cache-Hit == 1 |
| 212 | |
| 213 | # Identity is allowed by default even if another encoding is specified |
| 214 | txreq -url "/accept-encoding-identity" -hdr "Accept-Encoding: gzip" |
| 215 | rxresp |
| 216 | expect resp.status == 200 |
| 217 | expect resp.http.content-encoding == "<undef>" |
| 218 | expect resp.bodylen == 65 |
| 219 | expect resp.http.X-Cache-Hit == 1 |
| 220 | |
| 221 | # Refused identity encoding (explicit null weight) |
| 222 | txreq -url "/accept-encoding-identity" -hdr "Accept-Encoding: deflate, identity;q=0" |
| 223 | rxresp |
| 224 | expect resp.status == 200 |
| 225 | expect resp.http.content-encoding == "deflate" |
| 226 | expect resp.bodylen == 75 |
| 227 | expect resp.http.X-Cache-Hit == 0 |
| 228 | |
| 229 | |
| 230 | # |
| 231 | # Star tests |
| 232 | # |
| 233 | txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: *" |
| 234 | rxresp |
| 235 | expect resp.status == 200 |
| 236 | expect resp.http.content-encoding == "br" |
| 237 | expect resp.bodylen == 89 |
| 238 | expect resp.http.X-Cache-Hit == 0 |
| 239 | |
| 240 | # Regular case |
| 241 | txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: *" |
| 242 | rxresp |
| 243 | expect resp.status == 200 |
| 244 | expect resp.http.content-encoding == "br" |
| 245 | expect resp.bodylen == 89 |
| 246 | expect resp.http.X-Cache-Hit == 1 |
| 247 | |
| 248 | # Reject some encodings |
| 249 | txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: gzip;q=0, deflate,*" |
| 250 | rxresp |
| 251 | expect resp.status == 200 |
| 252 | expect resp.http.content-encoding == "br" |
| 253 | expect resp.bodylen == 89 |
| 254 | expect resp.http.X-Cache-Hit == 1 |
| 255 | |
| 256 | # Weighted star |
| 257 | txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: gzip;q=0, deflate,*;q=0.1" |
| 258 | rxresp |
| 259 | expect resp.status == 200 |
| 260 | expect resp.http.content-encoding == "br" |
| 261 | expect resp.bodylen == 89 |
| 262 | expect resp.http.X-Cache-Hit == 1 |
| 263 | |
| 264 | # Rejected identity |
| 265 | txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: gzip;q=0, deflate,*;q=0.1,identity;q=0" |
| 266 | rxresp |
| 267 | expect resp.status == 200 |
| 268 | expect resp.http.content-encoding == "br" |
| 269 | expect resp.bodylen == 89 |
| 270 | expect resp.http.X-Cache-Hit == 1 |
| 271 | |
| 272 | # Rejected star and "br" not accepted |
| 273 | txreq -url "/accept-encoding-star" -hdr "Accept-Encoding: gzip;q=0, deflate,*;q=0" |
| 274 | rxresp |
| 275 | expect resp.status == 200 |
| 276 | expect resp.http.content-encoding == "deflate" |
| 277 | expect resp.bodylen == 99 |
| 278 | expect resp.http.X-Cache-Hit == 0 |
| 279 | |
| 280 | |
| 281 | # |
| 282 | # Multiple content-encodings |
| 283 | # |
| 284 | txreq -url "/multiple-content-encoding" -hdr "Accept-Encoding: gzip;q=0.8, deflate" |
| 285 | rxresp |
| 286 | expect resp.status == 200 |
| 287 | expect resp.http.content-encoding == "deflate, gzip" |
| 288 | expect resp.bodylen == 109 |
| 289 | expect resp.http.X-Cache-Hit == 0 |
| 290 | |
| 291 | txreq -url "/multiple-content-encoding" -hdr "Accept-Encoding: deflate,gzip;q=0.7" |
| 292 | rxresp |
| 293 | expect resp.status == 200 |
| 294 | expect resp.http.content-encoding == "deflate, gzip" |
| 295 | expect resp.bodylen == 109 |
| 296 | expect resp.http.X-Cache-Hit == 1 |
| 297 | |
| 298 | |
| 299 | # |
| 300 | # Unknown content-encoding |
Remi Tricot-Le Breton | 6ca8916 | 2021-01-07 14:50:51 +0100 | [diff] [blame] | 301 | # 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] | 302 | # |
| 303 | txreq -url "/unknown-content-encoding" -hdr "Accept-Encoding: gzip;q=0.8, deflate, first_encoding" |
| 304 | rxresp |
| 305 | expect resp.status == 200 |
| 306 | expect resp.http.content-encoding == "unknown_encoding" |
| 307 | expect resp.bodylen == 119 |
| 308 | expect resp.http.X-Cache-Hit == 0 |
| 309 | |
| 310 | txreq -url "/unknown-content-encoding" -hdr "Accept-Encoding: deflate,gzip;q=0.8, first_encoding" |
| 311 | rxresp |
| 312 | expect resp.status == 200 |
| 313 | expect resp.http.content-encoding == "unknown_encoding" |
| 314 | expect resp.bodylen == 119 |
Remi Tricot-Le Breton | 14df1e1 | 2020-12-23 18:13:51 +0100 | [diff] [blame] | 315 | expect resp.http.X-Cache-Hit == 0 |
| 316 | |
Tim Duesterhus | dc38bc4 | 2020-12-29 12:43:53 +0100 | [diff] [blame] | 317 | # |
| 318 | # Hash collision (https://github.com/haproxy/haproxy/issues/988) |
| 319 | # |
| 320 | # crc32(gzip) ^ crc32(br) ^ crc32(xxx) ^ crc32(jdcqiab) == crc32(gzip) |
| 321 | txreq -url "/hash-collision" -hdr "Accept-Encoding: br,gzip,xxx,jdcqiab" |
| 322 | rxresp |
| 323 | expect resp.status == 200 |
| 324 | expect resp.http.content-encoding == "br" |
| 325 | expect resp.bodylen == 129 |
| 326 | expect resp.http.X-Cache-Hit == 0 |
| 327 | |
| 328 | txreq -url "/hash-collision" -hdr "Accept-Encoding: gzip" |
| 329 | rxresp |
| 330 | expect resp.status == 200 |
| 331 | expect resp.http.content-encoding == "gzip" |
| 332 | expect resp.bodylen == 139 |
| 333 | expect resp.http.X-Cache-Hit == 0 |
Remi Tricot-Le Breton | 14df1e1 | 2020-12-23 18:13:51 +0100 | [diff] [blame] | 334 | } -run |