Skip to content

Missing Vary: Accept header causes incorrect caching in content-negotiation #6916

@sanjana2505006

Description

@sanjana2505006

The example uses res.format() to send different responses (HTML, JSON, text) depending on what the client asks for using the Accept header.
But the example does not include the Vary: Accept header.

Without this header, caches (like CDNs or proxies) may save one version of the page and give that same version to every user—even if they asked for a different format.
This means someone asking for JSON might accidentally get HTML from the cache.
Adding:
res.vary('Accept')

before calling res.format() tells caches that the response depends on the Accept header, so each format is cached correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions