Skip to content

fix: send Vary: Accept on content-negotiated responses - #24

Merged
krokicki merged 2 commits into
mainfrom
fix-vary-accept
Jul 29, 2026
Merged

fix: send Vary: Accept on content-negotiated responses#24
krokicki merged 2 commits into
mainfrom
fix-vary-accept

Conversation

@krokicki

@krokicki krokicki commented Jul 29, 2026

Copy link
Copy Markdown
Member

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 the Accept header, but the responses never set Vary: Accept. The production nginx proxy_cache keys 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 without text/html in their Accept header, poisoning the cache with XML for browsers. A hard reload sends Cache-Control: no-cache, which the nginx config maps to proxy_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: Accept on both variants at the two negotiated fork points in target_dispatcher. nginx's proxy cache honors upstream Vary by default (since 1.7.7), so HTML and XML variants are now cached separately with no nginx changes required.

Testing

Added test_vary_accept_header covering both paths × both Accept types. Full suite: 71 passed.

@StephanPreibisch @allison-truhlar

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>
@krokicki
krokicki merged commit 7dcaaba into main Jul 29, 2026
5 checks passed
@krokicki
krokicki deleted the fix-vary-accept branch July 29, 2026 20:38
@krokicki

Copy link
Copy Markdown
Member Author

Thanks a lot for pointing out this problem, @allison-truhlar! It should be fixed in prod now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant