resthttpcachingcontent-negotiationvary

If the same URL can serve different content types shoud Vary include accept?


If the same URL can serve different content types for the same resource, must Vary include Accept ? Or do browser caches and proxies understand it as being implicit ?

Example:

GET /some/thing HTTP/1.1
Accept: application/json

This response

HTTP/1.1 200 OK
Transfer-Encoding: gzip
Content-Type: application/json
Cache-Control: max-age=3600, must-revalidate
Vary: Transfer-Encoding

{...}

or this one

HTTP/1.1 200 OK
Transfer-Encoding: gzip
Content-Type: application/json
Cache-Control: max-age=3600, must-revalidate
Vary: Transfer-Encoding, Accept

{...}

Solution

  • Actually the RFC does not indicate any kind of "implict" or special treatment of the content type (Accept) header...

    A Vary field value consisting of a comma-separated list of names indicates that the named request header fields, known as the selecting header fields, might have a role in selecting the representation.