Skip to content

Support for HTTP Vary configuration (e.g. in reaction to locale-based rendering) [SPR-14070] #18642

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions