Skip to content
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

MockHttpServletRequest changes Accept-Language header values [SPR-17566] #22098

spring-projects-issues opened this issue Dec 4, 2018 · 2 comments


Copy link

@spring-projects-issues spring-projects-issues commented Dec 4, 2018

Jan Engehausen opened SPR-17566 and commented


after switching to Spring 5 (via Spring Boot 2) I am unhappy with the behaviour of org.springframework.mock.web.MockHttpServletRequest in regards to handling the Accept-Language header. It seems that it is getting manipulated when values for this header are set. In short, I potentially do not get back the value I am setting. If I set a literal value, e.g. ru, fr;q=0.5, *;q=0.1 then I expect to get this back when I read it again. However, it gets transformed into e.g. ru, fr.

I am attaching a test showing the issue.

While I might work around this by subclassing the mock request where used directly, when I use fancier things like org.springframework.test.web.servlet.MockMvc this does not work (at least I don't know how). The request is built internally, and my code using that request sees the above demonstrated unexpected value.

public void testSomething() throws Exception {
 .header(HttpHeaders.ACCEPT_LANGUAGE, "ru, fr;q=0.5, *;q=0.1")

Suggestions on how to circumvent this problem or a fix would be appreciated!


Affects: 5.0.11, 5.1.3


Issue Links:

  • #20999 MockHttpServletRequest.addHeader fails for invalid LanguageRange in Accept-Language
  • #19773 Mock MVC / RequestBuilder should handle Accept-Language header appropriately

Backported to: 5.0.12

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 4, 2018

Juergen Hoeller commented

Fixed through preserving the original Accept-Language header value now, in addition to parsing the preferred locales.

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 4, 2018

Jan Engehausen commented

Thanks Juergen, that was a light speed job :) (y)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants