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