Skip to content

Mock MVC / RequestBuilder should handle Accept-Language header appropriately [SPR-15209] #19773

Closed
@spring-projects-issues

Description

@spring-projects-issues

Chris DaMour opened SPR-15209 and commented

we index all our data by locale, and we have an edge service normalize the accept-language request header for the given request.

I was trying to test this with mock mvc using the default boot locale resolver that just uses accept-language request header, but it did not work as expected.

This appears to be because MockHttpServletRequestBuilder and MockHttpServletRequest do not interpret the Accept-Language header at any point when implementing getLocale(). Since getLocale() is kind of fundamental to java servlet & AcceptHeaderLocaleResolver depends on this fundamentalness since it doesn't actually check the Accept-Language header directly, i think the mockers should be a little more knowledgeable about such a header.

however, I'm not sure if these are intentionally dumb. at some point the special handling of the Content-Type request header was removed from MockHttpServletRequest and that is a very similar case.

I'm not super comfortable with relying on locale() in my mock builder as it's not really verifying the incoming accept-language header is what's being respected.

If there's some direction i should follow i'd submit a PR


Affects: 4.3.6

Issue Links:

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions