Remi Tricot-Le Breton | 1785f3d | 2020-11-16 15:56:09 +0100 | [diff] [blame] | 1 | varnishtest "Vary support" |
| 2 | |
| 3 | #REQUIRE_VERSION=2.3 |
| 4 | |
| 5 | feature ignore_unknown_macro |
| 6 | |
| 7 | server s1 { |
| 8 | # Response varying on "accept-encoding" |
| 9 | rxreq |
| 10 | expect req.url == "/accept-encoding" |
| 11 | txresp -nolen -hdr "Transfer-Encoding: chunked" \ |
| 12 | -hdr "Content-Type: gzip" \ |
| 13 | -hdr "Vary: accept-encoding" \ |
| 14 | -hdr "Cache-Control: max-age=5" |
| 15 | chunkedlen 15 |
| 16 | chunkedlen 15 |
| 17 | chunkedlen 15 |
| 18 | chunkedlen 0 |
| 19 | |
| 20 | # Response varying on "accept-encoding" |
| 21 | rxreq |
| 22 | expect req.url == "/accept-encoding" |
| 23 | txresp -nolen -hdr "Transfer-Encoding: chunked" \ |
| 24 | -hdr "Content-Type: text/plain" \ |
| 25 | -hdr "Vary: accept-encoding" \ |
| 26 | -hdr "Cache-Control: max-age=5" |
| 27 | chunkedlen 16 |
| 28 | chunkedlen 16 |
| 29 | chunkedlen 16 |
| 30 | chunkedlen 0 |
| 31 | |
| 32 | # Response varying on "accept-encoding" but having two different encodings |
| 33 | rxreq |
| 34 | expect req.url == "/accept-encoding-multiple" |
| 35 | txresp -nolen -hdr "Transfer-Encoding: chunked" \ |
| 36 | -hdr "Vary: accept-encoding" \ |
| 37 | -hdr "Cache-Control: max-age=5" |
| 38 | chunkedlen 17 |
| 39 | chunkedlen 17 |
| 40 | chunkedlen 17 |
| 41 | chunkedlen 0 |
| 42 | |
| 43 | # Unmanaged vary |
| 44 | rxreq |
| 45 | expect req.url == "/unmanaged" |
| 46 | txresp -nolen -hdr "Transfer-Encoding: chunked" \ |
| 47 | -hdr "Vary: accept-encoding,unmanaged" \ |
| 48 | -hdr "Cache-Control: max-age=5" |
| 49 | chunkedlen 17 |
| 50 | chunkedlen 17 |
| 51 | chunkedlen 17 |
| 52 | chunkedlen 0 |
| 53 | |
| 54 | rxreq |
| 55 | expect req.url == "/unmanaged" |
| 56 | txresp -nolen -hdr "Transfer-Encoding: chunked" \ |
| 57 | -hdr "Vary: accept-encoding,unmanaged" \ |
| 58 | -hdr "Cache-Control: max-age=5" |
| 59 | chunkedlen 17 |
| 60 | chunkedlen 17 |
| 61 | chunkedlen 17 |
| 62 | chunkedlen 0 |
| 63 | |
| 64 | |
| 65 | # Mixed Vary (Accept-Encoding + Referer) |
| 66 | rxreq |
| 67 | expect req.url == "/referer-accept-encoding" |
| 68 | txresp -nolen -hdr "Transfer-Encoding: chunked" \ |
| 69 | -hdr "Vary: accept-encoding,referer" \ |
| 70 | -hdr "Cache-Control: max-age=5" |
| 71 | chunkedlen 17 |
| 72 | chunkedlen 17 |
| 73 | chunkedlen 17 |
| 74 | chunkedlen 0 |
| 75 | |
| 76 | rxreq |
| 77 | expect req.url == "/referer-accept-encoding" |
| 78 | txresp -nolen -hdr "Transfer-Encoding: chunked" \ |
| 79 | -hdr "Vary: referer,accept-encoding" \ |
| 80 | -hdr "Cache-Control: max-age=5" |
| 81 | chunkedlen 18 |
| 82 | chunkedlen 18 |
| 83 | chunkedlen 18 |
| 84 | chunkedlen 0 |
| 85 | |
| 86 | rxreq |
| 87 | expect req.url == "/referer-accept-encoding" |
| 88 | txresp -nolen -hdr "Transfer-Encoding: chunked" \ |
| 89 | -hdr "Vary: referer,accept-encoding" \ |
| 90 | -hdr "Cache-Control: max-age=5" |
| 91 | chunkedlen 19 |
| 92 | chunkedlen 19 |
| 93 | chunkedlen 19 |
| 94 | chunkedlen 0 |
| 95 | |
Remi Tricot-Le Breton | e4421de | 2020-12-23 18:13:46 +0100 | [diff] [blame] | 96 | # Multiple Accept-Encoding headers |
| 97 | rxreq |
| 98 | expect req.url == "/multiple_headers" |
| 99 | txresp -hdr "Vary: accept-encoding" \ |
| 100 | -hdr "Cache-Control: max-age=5" -bodylen 155 |
| 101 | |
| 102 | rxreq |
| 103 | expect req.url == "/multiple_headers" |
| 104 | txresp -hdr "Vary: accept-encoding" \ |
| 105 | -hdr "Cache-Control: max-age=5" -bodylen 166 |
| 106 | |
| 107 | |
| 108 | # Too many Accept-Encoding values (we will not cache responses with more than 16 encodings) |
| 109 | rxreq |
| 110 | expect req.url == "/too_many_encodings" |
| 111 | txresp -hdr "Vary: accept-encoding" \ |
| 112 | -hdr "Cache-Control: max-age=5" -bodylen 177 |
| 113 | |
| 114 | rxreq |
| 115 | expect req.url == "/too_many_encodings" |
| 116 | txresp -hdr "Vary: accept-encoding" \ |
| 117 | -hdr "Cache-Control: max-age=5" -bodylen 188 |
| 118 | |
Remi Tricot-Le Breton | 754b242 | 2020-11-16 15:56:10 +0100 | [diff] [blame] | 119 | |
| 120 | } -start |
| 121 | |
| 122 | server s2 { |
| 123 | # Responses that should not be cached |
| 124 | rxreq |
| 125 | expect req.url == "/no_vary_support" |
| 126 | txresp -nolen -hdr "Transfer-Encoding: chunked" \ |
| 127 | -hdr "Vary: accept-encoding" \ |
| 128 | -hdr "Cache-Control: max-age=5" |
| 129 | chunkedlen 19 |
| 130 | chunkedlen 19 |
| 131 | chunkedlen 19 |
| 132 | chunkedlen 0 |
| 133 | |
| 134 | rxreq |
| 135 | expect req.url == "/no_vary_support" |
| 136 | txresp -nolen -hdr "Transfer-Encoding: chunked" \ |
| 137 | -hdr "Vary: accept-encoding" \ |
| 138 | -hdr "Cache-Control: max-age=5" |
| 139 | chunkedlen 19 |
| 140 | chunkedlen 19 |
| 141 | chunkedlen 19 |
| 142 | chunkedlen 0 |
Remi Tricot-Le Breton | 1785f3d | 2020-11-16 15:56:09 +0100 | [diff] [blame] | 143 | } -start |
| 144 | |
| 145 | haproxy h1 -conf { |
| 146 | defaults |
| 147 | mode http |
| 148 | ${no-htx} option http-use-htx |
| 149 | timeout connect 1s |
| 150 | timeout client 1s |
| 151 | timeout server 1s |
| 152 | |
| 153 | frontend fe |
| 154 | bind "fd@${fe}" |
Remi Tricot-Le Breton | 754b242 | 2020-11-16 15:56:10 +0100 | [diff] [blame] | 155 | use_backend no_vary_be if { path_beg /no_vary_support } |
Remi Tricot-Le Breton | 1785f3d | 2020-11-16 15:56:09 +0100 | [diff] [blame] | 156 | default_backend test |
| 157 | |
| 158 | backend test |
| 159 | http-request cache-use my_cache |
| 160 | server www ${s1_addr}:${s1_port} |
| 161 | http-response cache-store my_cache |
| 162 | http-response set-header X-Cache-Hit %[res.cache_hit] |
| 163 | |
Remi Tricot-Le Breton | 754b242 | 2020-11-16 15:56:10 +0100 | [diff] [blame] | 164 | backend no_vary_be |
| 165 | http-request cache-use no_vary_cache |
| 166 | server www ${s2_addr}:${s2_port} |
| 167 | http-response cache-store no_vary_cache |
| 168 | http-response set-header X-Cache-Hit %[res.cache_hit] |
| 169 | |
Remi Tricot-Le Breton | 1785f3d | 2020-11-16 15:56:09 +0100 | [diff] [blame] | 170 | cache my_cache |
| 171 | total-max-size 3 |
| 172 | max-age 20 |
| 173 | max-object-size 3072 |
Remi Tricot-Le Breton | 754b242 | 2020-11-16 15:56:10 +0100 | [diff] [blame] | 174 | process-vary 1 |
| 175 | |
| 176 | cache no_vary_cache |
| 177 | total-max-size 3 |
| 178 | max-age 20 |
| 179 | max-object-size 3072 |
| 180 | process-vary 0 |
Remi Tricot-Le Breton | 1785f3d | 2020-11-16 15:56:09 +0100 | [diff] [blame] | 181 | } -start |
| 182 | |
| 183 | |
| 184 | client c1 -connect ${h1_fe_sock} { |
| 185 | # Accept-Encoding Vary |
| 186 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value" |
| 187 | rxresp |
| 188 | expect resp.status == 200 |
| 189 | expect resp.http.content-type == "gzip" |
| 190 | expect resp.bodylen == 45 |
| 191 | |
| 192 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value" |
| 193 | rxresp |
| 194 | expect resp.status == 200 |
| 195 | expect resp.bodylen == 48 |
| 196 | expect resp.http.content-type == "text/plain" |
| 197 | expect resp.http.X-Cache-Hit == 0 |
| 198 | |
| 199 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value" |
| 200 | rxresp |
| 201 | expect resp.status == 200 |
| 202 | expect resp.bodylen == 45 |
| 203 | expect resp.http.content-type == "gzip" |
| 204 | expect resp.http.X-Cache-Hit == 1 |
| 205 | |
| 206 | txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value" |
| 207 | rxresp |
| 208 | expect resp.status == 200 |
| 209 | expect resp.bodylen == 48 |
| 210 | expect resp.http.content-type == "text/plain" |
| 211 | expect resp.http.X-Cache-Hit == 1 |
| 212 | |
Remi Tricot-Le Breton | 8bb72aa | 2020-11-30 17:06:03 +0100 | [diff] [blame] | 213 | # The accept-encoding normalizer function converts the header values |
| 214 | # to lower case then calculates the hash of every sub part before |
| 215 | # sorting the hashes and xor'ing them (while removing duplicates). |
Remi Tricot-Le Breton | 1785f3d | 2020-11-16 15:56:09 +0100 | [diff] [blame] | 216 | txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second" |
| 217 | rxresp |
| 218 | expect resp.status == 200 |
| 219 | expect resp.bodylen == 51 |
| 220 | expect resp.http.X-Cache-Hit == 0 |
| 221 | |
| 222 | txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second" |
| 223 | rxresp |
| 224 | expect resp.status == 200 |
| 225 | expect resp.bodylen == 51 |
| 226 | expect resp.http.X-Cache-Hit == 1 |
| 227 | |
| 228 | txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: second,first" |
| 229 | rxresp |
| 230 | expect resp.status == 200 |
| 231 | expect resp.bodylen == 51 |
| 232 | expect resp.http.X-Cache-Hit == 1 |
| 233 | |
Remi Tricot-Le Breton | 8bb72aa | 2020-11-30 17:06:03 +0100 | [diff] [blame] | 234 | txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: FirsT,SECOND,first" |
| 235 | rxresp |
| 236 | expect resp.status == 200 |
| 237 | expect resp.bodylen == 51 |
| 238 | expect resp.http.X-Cache-Hit == 1 |
| 239 | |
Remi Tricot-Le Breton | 1785f3d | 2020-11-16 15:56:09 +0100 | [diff] [blame] | 240 | # Unmanaged vary |
| 241 | txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value" |
| 242 | rxresp |
| 243 | expect resp.status == 200 |
| 244 | expect resp.bodylen == 51 |
| 245 | expect resp.http.X-Cache-Hit == 0 |
| 246 | |
| 247 | txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value" |
| 248 | rxresp |
| 249 | expect resp.status == 200 |
| 250 | expect resp.bodylen == 51 |
| 251 | expect resp.http.X-Cache-Hit == 0 |
| 252 | |
| 253 | |
| 254 | # Mixed Vary (Accept-Encoding + Referer) |
| 255 | txreq -url "/referer-accept-encoding" \ |
| 256 | -hdr "Accept-Encoding: first_value,second_value" \ |
| 257 | -hdr "Referer: referer" |
| 258 | rxresp |
| 259 | expect resp.status == 200 |
| 260 | expect resp.bodylen == 51 |
| 261 | expect resp.http.X-Cache-Hit == 0 |
| 262 | |
| 263 | txreq -url "/referer-accept-encoding" \ |
| 264 | -hdr "Accept-Encoding: first_value" \ |
| 265 | -hdr "Referer: other-referer" |
| 266 | rxresp |
| 267 | expect resp.status == 200 |
| 268 | expect resp.bodylen == 54 |
| 269 | expect resp.http.X-Cache-Hit == 0 |
| 270 | |
| 271 | txreq -url "/referer-accept-encoding" \ |
| 272 | -hdr "Accept-Encoding: second_value" \ |
| 273 | -hdr "Referer: other-referer" |
| 274 | rxresp |
| 275 | expect resp.status == 200 |
| 276 | expect resp.bodylen == 57 |
| 277 | expect resp.http.X-Cache-Hit == 0 |
| 278 | |
| 279 | txreq -url "/referer-accept-encoding" \ |
| 280 | -hdr "Referer: referer" \ |
| 281 | -hdr "Accept-Encoding: second_value,first_value" |
| 282 | rxresp |
| 283 | expect resp.status == 200 |
| 284 | expect resp.bodylen == 51 |
| 285 | expect resp.http.X-Cache-Hit == 1 |
| 286 | |
| 287 | txreq -url "/referer-accept-encoding" \ |
| 288 | -hdr "Accept-Encoding: first_value" \ |
| 289 | -hdr "Referer: other-referer" |
| 290 | rxresp |
| 291 | expect resp.status == 200 |
| 292 | expect resp.bodylen == 54 |
| 293 | expect resp.http.X-Cache-Hit == 1 |
| 294 | |
| 295 | txreq -url "/referer-accept-encoding" \ |
| 296 | -hdr "Accept-Encoding: second_value" \ |
| 297 | -hdr "Referer: other-referer" |
| 298 | rxresp |
| 299 | expect resp.status == 200 |
| 300 | expect resp.bodylen == 57 |
| 301 | expect resp.http.X-Cache-Hit == 1 |
Remi Tricot-Le Breton | 754b242 | 2020-11-16 15:56:10 +0100 | [diff] [blame] | 302 | |
Remi Tricot-Le Breton | e4421de | 2020-12-23 18:13:46 +0100 | [diff] [blame] | 303 | |
| 304 | # Multiple Accept-encoding headers |
| 305 | txreq -url "/multiple_headers" \ |
| 306 | -hdr "Accept-Encoding: first_encoding" \ |
| 307 | -hdr "Accept-Encoding: second_encoding,third_encoding" |
| 308 | rxresp |
| 309 | expect resp.status == 200 |
| 310 | expect resp.bodylen == 155 |
| 311 | expect resp.http.X-Cache-Hit == 0 |
| 312 | |
| 313 | txreq -url "/multiple_headers" \ |
| 314 | -hdr "Accept-Encoding: third_encoding" \ |
| 315 | -hdr "Accept-Encoding: second_encoding,first_encoding" |
| 316 | rxresp |
| 317 | expect resp.status == 200 |
| 318 | expect resp.bodylen == 155 |
| 319 | expect resp.http.X-Cache-Hit == 1 |
| 320 | |
| 321 | # Should not match a cache entry |
| 322 | txreq -url "/multiple_headers" \ |
| 323 | -hdr "Accept-Encoding: first_encoding" |
| 324 | rxresp |
| 325 | expect resp.status == 200 |
| 326 | expect resp.bodylen == 166 |
| 327 | expect resp.http.X-Cache-Hit == 0 |
| 328 | |
| 329 | # Too many accept encodings |
| 330 | txreq -url "/too_many_encodings" \ |
| 331 | -hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17" |
| 332 | rxresp |
| 333 | expect resp.status == 200 |
| 334 | expect resp.bodylen == 177 |
| 335 | expect resp.http.X-Cache-Hit == 0 |
| 336 | |
| 337 | txreq -url "/too_many_encodings" \ |
| 338 | -hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17" |
| 339 | rxresp |
| 340 | expect resp.status == 200 |
| 341 | expect resp.bodylen == 188 |
| 342 | expect resp.http.X-Cache-Hit == 0 |
| 343 | |
| 344 | |
Remi Tricot-Le Breton | 8bb72aa | 2020-11-30 17:06:03 +0100 | [diff] [blame] | 345 | # The following requests are treated by a backend that does not cache |
Remi Tricot-Le Breton | 754b242 | 2020-11-16 15:56:10 +0100 | [diff] [blame] | 346 | # responses containing a Vary header |
| 347 | txreq -url "/no_vary_support" |
| 348 | rxresp |
| 349 | expect resp.status == 200 |
| 350 | expect resp.bodylen == 57 |
| 351 | expect resp.http.X-Cache-Hit == 0 |
| 352 | |
| 353 | txreq -url "/no_vary_support" |
| 354 | rxresp |
| 355 | expect resp.status == 200 |
| 356 | expect resp.bodylen == 57 |
| 357 | expect resp.http.X-Cache-Hit == 0 |
| 358 | |
| 359 | |
Remi Tricot-Le Breton | 1785f3d | 2020-11-16 15:56:09 +0100 | [diff] [blame] | 360 | } -run |