Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Jan 31, 2017 · 3 comments
Assignees
Labels
in: test Issues in the test module type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 31, 2017

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:

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

So you're currently setting the Accept-Language header in your tests? I'm wondering why not just use the locale methods on MockHttpServletRequestBuilder? We could add special handling for the Accept-Language header. That would be merely a convenience, it doesn't add value from an integration testing perspective since it's not the Servlet container parsing the headers.

@spring-projects-issues
Copy link
Collaborator Author

Chris DaMour commented

i do have tests with locale...but then anything that calls getHeader("accept-language") doesn't sync up
as mentioned in description:

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.

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

Right I see it now. AcceptHeaderLocaleResolver relies on request.getLocale() but in 4.3 there was an extra check added for the presence of Accept-Language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants