Skip to content

Commit 7f67e63

Browse files
committed
Add Accept-Encoding header to cache key
Most webservers respond with `Vary: Accept-Encoding` when presented with the `Accept-Encoding` header, which causes Nginx to automatically include the request header as part of the cache key. Unfortunately, issue #8 shows that at least GitLab does not respond with the expected `Vary` header causing the cache key to be too broad. For example, if you sent a specific request to Velocita with `Accept-Encoding` set to `br`, the Brotli-encoded response would be cached. If you would then perform the same request _without_ the `Accept-Encoding` header, you would erroneously receive that same Brotli-encoded response. Fix this by always including the value of the `Accept-Encoding` request header in the cache key.
1 parent 44dc23b commit 7f67e63

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

proxy/templates/proxy.conf.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ access_log /var/log/nginx/access.log upstreamlog;
5757
# Caching configuration
5858
proxy_cache_background_update on;
5959
proxy_cache_convert_head off;
60-
proxy_cache_key $request_method$scheme$proxy_host$request_uri;
60+
proxy_cache_key "$request_method $scheme $http_accept_encoding $proxy_host $request_uri";
6161
proxy_cache_lock on;
6262
proxy_cache_use_stale error timeout updating http_403 http_404 http_429 http_500 http_502 http_503 http_504;
6363
proxy_cache_valid 200 302 1d;

0 commit comments

Comments
 (0)