fix: send Vary: Accept on content-negotiated responses - #24
Merged
Conversation
The index and bucket browse URLs serve either HTML or XML depending on the Accept header. Without Vary: Accept, a shared cache (e.g. the production nginx proxy_cache) stores whichever variant was requested first and serves it to all clients, so browsers intermittently receive the ListBuckets XML instead of the HTML index. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Member
Author
|
Thanks a lot for pointing out this problem, @allison-truhlar! It should be fixed in prod now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In production, the initial browser load of the index page often shows the ListBuckets XML instead of the HTML index; reloading then shows the HTML. Not reproducible in local deployments.
Root cause
The index (
/) and bucket browse (/{bucket}/) URLs serve either HTML or XML for the same URL, negotiated purely on theAcceptheader, but the responses never setVary: Accept. The production nginxproxy_cachekeys only on scheme/host/method/URI, so whichever variant is requested first after cache expiry is cached and served to everyone for 15 minutes. S3 clients (aws cli, neuroglancer, monitors) frequently hit/for ListBuckets withouttext/htmlin their Accept header, poisoning the cache with XML for browsers. A hard reload sendsCache-Control: no-cache, which the nginx config maps toproxy_cache_bypass, refreshing the entry with HTML — hence "reload fixes it".Local deployments have no shared cache in front, so the bug never appears there.
Fix
Set
Vary: Accepton both variants at the two negotiated fork points intarget_dispatcher. nginx's proxy cache honors upstreamVaryby default (since 1.7.7), so HTML and XML variants are now cached separately with no nginx changes required.Testing
Added
test_vary_accept_headercovering both paths × both Accept types. Full suite: 71 passed.@StephanPreibisch @allison-truhlar