Description
Markus Malkusch opened SPR-14070 and commented
An i18n webapplication might use the AcceptHeaderLocaleResolver
do deliver content in different languages based on the accept-language
HTTP header.
To inform user agents and cache proxies about that kind of content negotiation, HTTP provides the VARY
header.
Vary: accept-language
I suggest that Spring transparently sets an appropriate VARY
header to the HTTP response if an AcceptHeaderLocaleResolver
bean is used.
Also I don't see a point in using AcceptHeaderLocaleResolver
without a VARY
header. In fact applications doing so are broken, as an intermediate cache proxy might deliver a cached response of a wrong language. So I further suggest setting the VARY
header should be a default behaviour (if AcceptHeaderLocaleResolver
is used). That's also the RFCs wording as well:
An origin server SHOULD send a Vary header field when its algorithm
for selecting a representation varies based on aspects of the request
message other than the method and request target, unless the variance
cannot be crossed or the origin server has been deliberately
configured to prevent cache transparency.
Settings the VARY
header appropriatly means, taking into account that the response might have such a header already. In this case, it needs to be determined if adding accept-language is necessary. It's not necessary, if the existing header is "*" or contains already "accept-language".
Reference URL: https://tools.ietf.org/html/rfc7231#section-7.1.4
Issue Links:
- Spring should have default support for OPTIONS, HEAD and Allow [SPR-13130] #17721 Spring should have default support for OPTIONS, HEAD and Allow
- Flexible locale resolution based on supported languages [SPR-13330] #17915 Flexible locale resolution based on supported languages
- HttpEntityMethodProcessor discards headers [SPR-15952] #20504 HttpEntityMethodProcessor discards headers
- ResponseEntity should allow the usage of unassigned HTTP status codes [SPR-14205] #18779 ResponseEntity should allow the usage of unassigned HTTP status codes