Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vary header should include Accept if a resource can be HTML and JSON #3512

Open
lo48576 opened this issue Feb 22, 2025 · 0 comments
Open

Vary header should include Accept if a resource can be HTML and JSON #3512

lo48576 opened this issue Feb 22, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@lo48576
Copy link
Contributor

lo48576 commented Feb 22, 2025

Describe the bug

Dynamic pages that can return HTML or JSON (e.g., /users/{username}) should include Accept to Vary response header, but they don't.

This leads to wrongly cached user profile.
In my case, Cloudflare Tunnel caches a JSON representation for my profile page and returns it for normal browser access (including private browsing with no cookies and no browser caches).

To Reproduce

  1. Get the user profile page with wget -qS -O https://{domain}/user/{username}.
  2. See the Vary header. It is Accept-Language, Cookie.
  3. Get the JSON version of user profile page, with wget -qS -O https://{domain}/user/{username} --header 'Accept: application/json'.
  4. See the Vary header. It is still Accept-Language, Cookie.

Expected behavior

Vary header for those pages should include Accept header, since it returns different responses for different Accept values (typically for text/html and application/json (or application/activity+json for ActivityPub protocol)).

Screenshots

Vary header:

$ wget -qS -O - http://localhost:8080/user/nop_thread --header 'Accept: application/activity+json' 2>&1 | grep Vary:
  Vary: Accept-Language, Cookie
$

Cloudflare cache issue:

Cloudflare Tunnel returns JSON representation for a request from browser

Cloudflare Tunnel returns JSON representation for a request with 'Accept: text/html'

Instance

https://bookwyrm.nops.red/
(I'll purge and workaround the cache issue, so the JSON-returned-to-browser issue will become non-reproducible soon.)

Additional context

N/A

@lo48576 lo48576 added the bug Something isn't working label Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant