Description
Jan Engehausen opened SPR-17566 and commented
Greetings,
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 {
mockMvc.perform(
get("/my/controller/url")
.header(HttpHeaders.ACCEPT_LANGUAGE, "ru, fr;q=0.5, *;q=0.1")
)
.andExpect(status().isOk());
)
Suggestions on how to circumvent this problem or a fix would be appreciated!
Thanks,
Jan
Affects: 5.0.11, 5.1.3
Attachments:
- lang-tag-demo.zip (3.62 kB)
Issue Links:
- MockHttpServletRequest.addHeader fails for invalid LanguageRange in Accept-Language [SPR-16454] #20999 MockHttpServletRequest.addHeader fails for invalid LanguageRange in Accept-Language
- Mock MVC / RequestBuilder should handle Accept-Language header appropriately [SPR-15209] #19773 Mock MVC / RequestBuilder should handle Accept-Language header appropriately
Backported to: 5.0.12