2020-11-16 14:56:09 +00:00
|
|
|
varnishtest "Vary support"
|
|
|
|
|
|
|
|
#REQUIRE_VERSION=2.3
|
|
|
|
|
|
|
|
feature ignore_unknown_macro
|
|
|
|
|
|
|
|
server s1 {
|
|
|
|
# Response varying on "accept-encoding"
|
|
|
|
rxreq
|
|
|
|
expect req.url == "/accept-encoding"
|
2020-12-23 17:13:50 +00:00
|
|
|
txresp -hdr "Content-Encoding: gzip" \
|
2020-11-16 14:56:09 +00:00
|
|
|
-hdr "Vary: accept-encoding" \
|
2020-12-23 17:13:50 +00:00
|
|
|
-hdr "Cache-Control: max-age=5" \
|
|
|
|
-bodylen 45
|
2020-11-16 14:56:09 +00:00
|
|
|
|
|
|
|
# Response varying on "accept-encoding"
|
|
|
|
rxreq
|
|
|
|
expect req.url == "/accept-encoding"
|
2020-12-23 17:13:50 +00:00
|
|
|
txresp -hdr "Content-Type: text/plain" \
|
2020-11-16 14:56:09 +00:00
|
|
|
-hdr "Vary: accept-encoding" \
|
2020-12-23 17:13:50 +00:00
|
|
|
-hdr "Cache-Control: max-age=5" \
|
|
|
|
-bodylen 48
|
2020-11-16 14:56:09 +00:00
|
|
|
|
|
|
|
# Response varying on "accept-encoding" but having two different encodings
|
|
|
|
rxreq
|
|
|
|
expect req.url == "/accept-encoding-multiple"
|
2020-12-23 17:13:50 +00:00
|
|
|
txresp -hdr "Vary: accept-encoding" \
|
|
|
|
-hdr "Cache-Control: max-age=5" \
|
|
|
|
-bodylen 51
|
|
|
|
|
2020-11-16 14:56:09 +00:00
|
|
|
|
|
|
|
# Unmanaged vary
|
|
|
|
rxreq
|
|
|
|
expect req.url == "/unmanaged"
|
2020-12-23 17:13:50 +00:00
|
|
|
txresp -hdr "Vary: accept-encoding,unmanaged" \
|
|
|
|
-hdr "Cache-Control: max-age=5" \
|
|
|
|
-bodylen 51
|
|
|
|
|
2020-11-16 14:56:09 +00:00
|
|
|
|
|
|
|
rxreq
|
|
|
|
expect req.url == "/unmanaged"
|
2020-12-23 17:13:50 +00:00
|
|
|
txresp -hdr "Vary: accept-encoding,unmanaged" \
|
|
|
|
-hdr "Cache-Control: max-age=5" \
|
|
|
|
-bodylen 51
|
|
|
|
|
2020-11-16 14:56:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Mixed Vary (Accept-Encoding + Referer)
|
|
|
|
rxreq
|
|
|
|
expect req.url == "/referer-accept-encoding"
|
2020-12-23 17:13:50 +00:00
|
|
|
txresp -hdr "Vary: accept-encoding,referer" \
|
|
|
|
-hdr "Cache-Control: max-age=5" \
|
|
|
|
-hdr "Content-Encoding: gzip" \
|
|
|
|
-bodylen 51
|
2020-11-16 14:56:09 +00:00
|
|
|
|
|
|
|
rxreq
|
|
|
|
expect req.url == "/referer-accept-encoding"
|
2020-12-23 17:13:50 +00:00
|
|
|
txresp -hdr "Vary: referer,accept-encoding" \
|
|
|
|
-hdr "Cache-Control: max-age=5" \
|
|
|
|
-hdr "Content-Encoding: gzip" \
|
|
|
|
-bodylen 54
|
2020-11-16 14:56:09 +00:00
|
|
|
|
|
|
|
rxreq
|
|
|
|
expect req.url == "/referer-accept-encoding"
|
2020-12-23 17:13:50 +00:00
|
|
|
txresp -hdr "Vary: referer,accept-encoding" \
|
|
|
|
-hdr "Cache-Control: max-age=5" \
|
|
|
|
-hdr "Content-Encoding: gzip" \
|
|
|
|
-bodylen 57
|
2020-11-16 14:56:09 +00:00
|
|
|
|
2020-12-23 17:13:46 +00:00
|
|
|
# Multiple Accept-Encoding headers
|
|
|
|
rxreq
|
|
|
|
expect req.url == "/multiple_headers"
|
|
|
|
txresp -hdr "Vary: accept-encoding" \
|
2020-12-23 17:13:50 +00:00
|
|
|
-hdr "Cache-Control: max-age=5" \
|
|
|
|
-hdr "Content-Encoding: gzip" \
|
|
|
|
-bodylen 155
|
2020-12-23 17:13:46 +00:00
|
|
|
|
|
|
|
rxreq
|
|
|
|
expect req.url == "/multiple_headers"
|
|
|
|
txresp -hdr "Vary: accept-encoding" \
|
2020-12-23 17:13:50 +00:00
|
|
|
-hdr "Cache-Control: max-age=5" \
|
|
|
|
-hdr "Content-Encoding: gzip" \
|
|
|
|
-bodylen 166
|
2020-12-23 17:13:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Too many Accept-Encoding values (we will not cache responses with more than 16 encodings)
|
|
|
|
rxreq
|
|
|
|
expect req.url == "/too_many_encodings"
|
|
|
|
txresp -hdr "Vary: accept-encoding" \
|
2020-12-23 17:13:50 +00:00
|
|
|
-hdr "Cache-Control: max-age=5" \
|
|
|
|
-hdr "Content-Encoding: gzip" \
|
|
|
|
-bodylen 177
|
2020-12-23 17:13:46 +00:00
|
|
|
|
|
|
|
rxreq
|
|
|
|
expect req.url == "/too_many_encodings"
|
|
|
|
txresp -hdr "Vary: accept-encoding" \
|
2020-12-23 17:13:50 +00:00
|
|
|
-hdr "Cache-Control: max-age=5" \
|
|
|
|
-hdr "Content-Encoding: gzip" \
|
|
|
|
-bodylen 188
|
2020-12-23 17:13:46 +00:00
|
|
|
|
2020-11-16 14:56:10 +00:00
|
|
|
|
|
|
|
} -start
|
|
|
|
|
|
|
|
server s2 {
|
|
|
|
# Responses that should not be cached
|
|
|
|
rxreq
|
|
|
|
expect req.url == "/no_vary_support"
|
2020-12-23 17:13:50 +00:00
|
|
|
txresp -hdr "Vary: accept-encoding" \
|
|
|
|
-hdr "Cache-Control: max-age=5" \
|
|
|
|
-bodylen 57
|
2020-11-16 14:56:10 +00:00
|
|
|
|
|
|
|
rxreq
|
|
|
|
expect req.url == "/no_vary_support"
|
2020-12-23 17:13:50 +00:00
|
|
|
txresp -hdr "Vary: accept-encoding" \
|
|
|
|
-hdr "Cache-Control: max-age=5" \
|
|
|
|
-bodylen 57
|
2020-11-16 14:56:09 +00:00
|
|
|
} -start
|
|
|
|
|
|
|
|
haproxy h1 -conf {
|
|
|
|
defaults
|
|
|
|
mode http
|
|
|
|
${no-htx} option http-use-htx
|
|
|
|
timeout connect 1s
|
|
|
|
timeout client 1s
|
|
|
|
timeout server 1s
|
|
|
|
|
|
|
|
frontend fe
|
|
|
|
bind "fd@${fe}"
|
2020-11-16 14:56:10 +00:00
|
|
|
use_backend no_vary_be if { path_beg /no_vary_support }
|
2020-11-16 14:56:09 +00:00
|
|
|
default_backend test
|
|
|
|
|
|
|
|
backend test
|
|
|
|
http-request cache-use my_cache
|
|
|
|
server www ${s1_addr}:${s1_port}
|
|
|
|
http-response cache-store my_cache
|
|
|
|
http-response set-header X-Cache-Hit %[res.cache_hit]
|
|
|
|
|
2020-11-16 14:56:10 +00:00
|
|
|
backend no_vary_be
|
|
|
|
http-request cache-use no_vary_cache
|
|
|
|
server www ${s2_addr}:${s2_port}
|
|
|
|
http-response cache-store no_vary_cache
|
|
|
|
http-response set-header X-Cache-Hit %[res.cache_hit]
|
|
|
|
|
2020-11-16 14:56:09 +00:00
|
|
|
cache my_cache
|
|
|
|
total-max-size 3
|
|
|
|
max-age 20
|
|
|
|
max-object-size 3072
|
2020-11-16 14:56:10 +00:00
|
|
|
process-vary 1
|
|
|
|
|
|
|
|
cache no_vary_cache
|
|
|
|
total-max-size 3
|
|
|
|
max-age 20
|
|
|
|
max-object-size 3072
|
|
|
|
process-vary 0
|
2020-11-16 14:56:09 +00:00
|
|
|
} -start
|
|
|
|
|
|
|
|
|
|
|
|
client c1 -connect ${h1_fe_sock} {
|
|
|
|
# Accept-Encoding Vary
|
|
|
|
txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
2020-12-23 17:13:50 +00:00
|
|
|
expect resp.http.content-encoding == "gzip"
|
2020-11-16 14:56:09 +00:00
|
|
|
expect resp.bodylen == 45
|
|
|
|
|
|
|
|
txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 48
|
|
|
|
expect resp.http.content-type == "text/plain"
|
|
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
|
|
|
|
txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 45
|
2020-12-23 17:13:50 +00:00
|
|
|
expect resp.http.content-encoding == "gzip"
|
2020-11-16 14:56:09 +00:00
|
|
|
expect resp.http.X-Cache-Hit == 1
|
|
|
|
|
|
|
|
txreq -url "/accept-encoding" -hdr "Accept-Encoding: second_value"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 48
|
|
|
|
expect resp.http.content-type == "text/plain"
|
|
|
|
expect resp.http.X-Cache-Hit == 1
|
|
|
|
|
2020-11-30 16:06:03 +00:00
|
|
|
# The accept-encoding normalizer function converts the header values
|
|
|
|
# to lower case then calculates the hash of every sub part before
|
|
|
|
# sorting the hashes and xor'ing them (while removing duplicates).
|
2020-11-16 14:56:09 +00:00
|
|
|
txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 51
|
|
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
|
|
|
|
txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: first,second"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 51
|
|
|
|
expect resp.http.X-Cache-Hit == 1
|
|
|
|
|
|
|
|
txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: second,first"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 51
|
|
|
|
expect resp.http.X-Cache-Hit == 1
|
|
|
|
|
2020-11-30 16:06:03 +00:00
|
|
|
txreq -url "/accept-encoding-multiple" -hdr "Accept-Encoding: FirsT,SECOND,first"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 51
|
|
|
|
expect resp.http.X-Cache-Hit == 1
|
|
|
|
|
2020-11-16 14:56:09 +00:00
|
|
|
# Unmanaged vary
|
|
|
|
txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 51
|
|
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
|
|
|
|
txreq -url "/unmanaged" -hdr "Accept-Encoding: first_value"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 51
|
|
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
|
|
|
|
|
|
|
|
# Mixed Vary (Accept-Encoding + Referer)
|
|
|
|
txreq -url "/referer-accept-encoding" \
|
|
|
|
-hdr "Accept-Encoding: first_value,second_value" \
|
|
|
|
-hdr "Referer: referer"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 51
|
|
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
|
|
|
|
txreq -url "/referer-accept-encoding" \
|
|
|
|
-hdr "Accept-Encoding: first_value" \
|
|
|
|
-hdr "Referer: other-referer"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 54
|
|
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
|
|
|
|
txreq -url "/referer-accept-encoding" \
|
|
|
|
-hdr "Accept-Encoding: second_value" \
|
|
|
|
-hdr "Referer: other-referer"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 57
|
|
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
|
|
|
|
txreq -url "/referer-accept-encoding" \
|
|
|
|
-hdr "Referer: referer" \
|
|
|
|
-hdr "Accept-Encoding: second_value,first_value"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 51
|
|
|
|
expect resp.http.X-Cache-Hit == 1
|
|
|
|
|
|
|
|
txreq -url "/referer-accept-encoding" \
|
|
|
|
-hdr "Accept-Encoding: first_value" \
|
|
|
|
-hdr "Referer: other-referer"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 54
|
|
|
|
expect resp.http.X-Cache-Hit == 1
|
|
|
|
|
|
|
|
txreq -url "/referer-accept-encoding" \
|
|
|
|
-hdr "Accept-Encoding: second_value" \
|
|
|
|
-hdr "Referer: other-referer"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 57
|
|
|
|
expect resp.http.X-Cache-Hit == 1
|
2020-11-16 14:56:10 +00:00
|
|
|
|
2020-12-23 17:13:46 +00:00
|
|
|
|
|
|
|
# Multiple Accept-encoding headers
|
|
|
|
txreq -url "/multiple_headers" \
|
|
|
|
-hdr "Accept-Encoding: first_encoding" \
|
|
|
|
-hdr "Accept-Encoding: second_encoding,third_encoding"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 155
|
|
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
|
|
|
|
txreq -url "/multiple_headers" \
|
|
|
|
-hdr "Accept-Encoding: third_encoding" \
|
|
|
|
-hdr "Accept-Encoding: second_encoding,first_encoding"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 155
|
|
|
|
expect resp.http.X-Cache-Hit == 1
|
|
|
|
|
|
|
|
# Should not match a cache entry
|
|
|
|
txreq -url "/multiple_headers" \
|
|
|
|
-hdr "Accept-Encoding: first_encoding"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 166
|
|
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
|
|
|
|
# Too many accept encodings
|
|
|
|
txreq -url "/too_many_encodings" \
|
|
|
|
-hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 177
|
|
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
|
|
|
|
txreq -url "/too_many_encodings" \
|
|
|
|
-hdr "Accept-Encoding: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 188
|
|
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
|
|
|
|
|
2020-11-30 16:06:03 +00:00
|
|
|
# The following requests are treated by a backend that does not cache
|
2020-11-16 14:56:10 +00:00
|
|
|
# responses containing a Vary header
|
|
|
|
txreq -url "/no_vary_support"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 57
|
|
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
|
|
|
|
txreq -url "/no_vary_support"
|
|
|
|
rxresp
|
|
|
|
expect resp.status == 200
|
|
|
|
expect resp.bodylen == 57
|
|
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
|
|
|
|
|
2020-11-16 14:56:09 +00:00
|
|
|
} -run
|