blob: 001018f93c55f54e301c1932e14f7c86a5f756e6 [file] [log] [blame]
varnishtest "Vary support"
#REQUIRE_VERSION=2.3
feature ignore_unknown_macro
server s1 {
# Response varying on "accept-encoding"
rxreq
expect req.url == "/accept-encoding"
txresp -nolen -hdr "Transfer-Encoding: chunked" \
-hdr "Content-Type: gzip" \
-hdr "Vary: accept-encoding" \
-hdr "Cache-Control: max-age=5"
chunkedlen 15
chunkedlen 15
chunkedlen 15
chunkedlen 0
# Response varying on "accept-encoding"
rxreq
expect req.url == "/accept-encoding"
txresp -nolen -hdr "Transfer-Encoding: chunked" \
-hdr "Content-Type: text/plain" \
-hdr "Vary: accept-encoding" \
-hdr "Cache-Control: max-age=5"
chunkedlen 16
chunkedlen 16
chunkedlen 16
chunkedlen 0
# Response varying on "accept-encoding" but having two different encodings
rxreq
expect req.url == "/accept-encoding-multiple"
txresp -nolen -hdr "Transfer-Encoding: chunked" \
-hdr "Vary: accept-encoding" \
-hdr "Cache-Control: max-age=5"
chunkedlen 17
chunkedlen 17
chunkedlen 17
chunkedlen 0
# Unmanaged vary
rxreq
expect req.url == "/unmanaged"
txresp -nolen -hdr "Transfer-Encoding: chunked" \
-hdr "Vary: accept-encoding,unmanaged" \
-hdr "Cache-Control: max-age=5"
chunkedlen 17
chunkedlen 17
chunkedlen 17
chunkedlen 0
rxreq
expect req.url == "/unmanaged"
txresp -nolen -hdr "Transfer-Encoding: chunked" \
-hdr "Vary: accept-encoding,unmanaged" \
-hdr "Cache-Control: max-age=5"
chunkedlen 17
chunkedlen 17
chunkedlen 17
chunkedlen 0
# Mixed Vary (Accept-Encoding + Referer)
rxreq
expect req.url == "/referer-accept-encoding"
txresp -nolen -hdr "Transfer-Encoding: chunked" \
-hdr "Vary: accept-encoding,referer" \
-hdr "Cache-Control: max-age=5"
chunkedlen 17
chunkedlen 17
chunkedlen 17
chunkedlen 0
rxreq
expect req.url == "/referer-accept-encoding"
txresp -nolen -hdr "Transfer-Encoding: chunked" \
-hdr "Vary: referer,accept-encoding" \
-hdr "Cache-Control: max-age=5"
chunkedlen 18
chunkedlen 18
chunkedlen 18
chunkedlen 0
rxreq
expect req.url == "/referer-accept-encoding"
txresp -nolen -hdr "Transfer-Encoding: chunked" \
-hdr "Vary: referer,accept-encoding" \
-hdr "Cache-Control: max-age=5"
chunkedlen 19
chunkedlen 19
chunkedlen 19
chunkedlen 0
} -start
server s2 {
# Responses that should not be cached
rxreq
expect req.url == "/no_vary_support"
txresp -nolen -hdr "Transfer-Encoding: chunked" \
-hdr "Vary: accept-encoding" \
-hdr "Cache-Control: max-age=5"
chunkedlen 19
chunkedlen 19
chunkedlen 19
chunkedlen 0
rxreq
expect req.url == "/no_vary_support"
txresp -nolen -hdr "Transfer-Encoding: chunked" \
-hdr "Vary: accept-encoding" \
-hdr "Cache-Control: max-age=5"
chunkedlen 19
chunkedlen 19
chunkedlen 19
chunkedlen 0
} -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}"
use_backend no_vary_be if { path_beg /no_vary_support }
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]
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]
cache my_cache
total-max-size 3
max-age 20
max-object-size 3072
process-vary 1
cache no_vary_cache
total-max-size 3
max-age 20
max-object-size 3072
process-vary 0
} -start
client c1 -connect ${h1_fe_sock} {
# Accept-Encoding Vary
txreq -url "/accept-encoding" -hdr "Accept-Encoding: first_value"
rxresp
expect resp.status == 200
expect resp.http.content-type == "gzip"
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
expect resp.http.content-type == "gzip"
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
# 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).
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
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
# 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
# The following requests are treated by a backend that does not cache
# 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
} -run