zazuko/varnish-post

cache is insensitive to `Accept`/`Content-Type`

Opened this issue · 0 comments

The cache doesn't consider the Accept request header. In some rare edge cases this can lead to the wrong format being sent.

repro steps:

# first query priming the cache
curl https://lindas-cached.test.cluster.ldbar.ch/query -H 'Accept: application/n-quads' --data-raw 'query=DESCRIBE%20%3Chttps%3A%2F%2Fld.admin.ch%2Fcanton%2F2%3E'

# second query reusing the cache - but delivering the wrong format
curl https://lindas-cached.test.cluster.ldbar.ch/query -H 'Accept: application/n-triples' --data-raw 'query=DESCRIBE%20%3Chttps%3A%2F%2Fld.admin.ch%2Fcanton%2F2%3E'

# Alter the hashing method to include POST bodies
# See: https://docs.varnish-software.com/tutorials/caching-post-requests/#step-3-change-the-hashing-function
sub vcl_hash {
hash_data(req.http.Authorization);
hash_data(req.url);
if (req.http.X-Body-Len) {
bodyaccess.hash_req_body();
} else {
hash_data("");
}
return (lookup);
}