-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Closed
Labels
in: testIssues in the test moduleIssues in the test modulestatus: backportedAn issue that has been backported to maintenance branchesAn issue that has been backported to maintenance branchestype: bugA general bugA general bug
Milestone
Description
Affects: 6.x+
It seems that if we provide multiple values for CONTENT_LANGUAGE
as an array like:
ResponseEntity.ok()
.header(HttpHeaders.CONTENT_LANGUAGE, contentLanguage.toArray(new String[0]))
.body(body);
It won't work nicely with MockHttpServletResponse
.
The logic we have there in setSpecialHeader
method:
spring-framework/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java
Lines 756 to 767 in 8b14bf8
else if (HttpHeaders.CONTENT_LANGUAGE.equalsIgnoreCase(name)) { | |
String contentLanguages = value.toString(); | |
HttpHeaders headers = new HttpHeaders(); | |
headers.add(HttpHeaders.CONTENT_LANGUAGE, contentLanguages); | |
Locale language = headers.getContentLanguage(); | |
setLocale(language != null ? language : Locale.getDefault()); | |
// Since setLocale() sets the Content-Language header to the given | |
// single Locale, we have to explicitly set the Content-Language header | |
// to the user-provided value. | |
doAddHeaderValue(HttpHeaders.CONTENT_LANGUAGE, contentLanguages, true); | |
return true; | |
} |
expects that all the values are sent in a value
.
but from debugging, I saw that ServletServerHttpResponse
will call setSpecialHeader
of MockHttpServletResponse
for each header's value.
Lines 113 to 119 in 8b14bf8
private void writeHeaders() { | |
if (!this.headersWritten) { | |
getHeaders().forEach((headerName, headerValues) -> { | |
for (String headerValue : headerValues) { | |
this.servletResponse.addHeader(headerName, headerValue); | |
} | |
}); |
Thus, only the last value will be present in the response.
Metadata
Metadata
Assignees
Labels
in: testIssues in the test moduleIssues in the test modulestatus: backportedAn issue that has been backported to maintenance branchesAn issue that has been backported to maintenance branchestype: bugA general bugA general bug