Merge branch '6.2.x'

This commit is contained in:
Brian Clozel
2025-02-25 17:19:01 +01:00
3 changed files with 30 additions and 17 deletions

View File

@@ -755,14 +755,17 @@ public class MockHttpServletResponse implements HttpServletResponse {
}
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);
// only set the locale if we replace the header or if there was none before
if (replaceHeader || !this.headers.containsKey(HttpHeaders.CONTENT_LANGUAGE)) {
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_LANGUAGE, contentLanguages);
Locale language = headers.getContentLanguage();
this.locale = language != null ? language : Locale.getDefault();
doAddHeaderValue(HttpHeaders.CONTENT_LANGUAGE, contentLanguages, replaceHeader);
}
else {
doAddHeaderValue(HttpHeaders.CONTENT_LANGUAGE, contentLanguages, false);
}
return true;
}
else if (HttpHeaders.SET_COOKIE.equalsIgnoreCase(name)) {

View File

@@ -290,6 +290,14 @@ class MockHttpServletResponseTests {
assertThat(response.getLocale()).isEqualTo(Locale.ITALIAN);
}
@Test // gh-34488
void shouldAddMultipleContentLanguage() {
response.addHeader(HttpHeaders.CONTENT_LANGUAGE, "en");
response.addHeader(HttpHeaders.CONTENT_LANGUAGE, "fr");
assertThat(response.getHeaders(HttpHeaders.CONTENT_LANGUAGE)).contains("en", "fr");
assertThat(response.getLocale()).isEqualTo(Locale.ENGLISH);
}
@Test
void contentLengthSetsHeader() {
response.setContentLength(66);
@@ -672,5 +680,4 @@ class MockHttpServletResponseTests {
}
}

View File

@@ -755,14 +755,17 @@ public class MockHttpServletResponse implements HttpServletResponse {
}
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);
// only set the locale if we replace the header or if there was none before
if (replaceHeader || !this.headers.containsKey(HttpHeaders.CONTENT_LANGUAGE)) {
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_LANGUAGE, contentLanguages);
Locale language = headers.getContentLanguage();
this.locale = language != null ? language : Locale.getDefault();
doAddHeaderValue(HttpHeaders.CONTENT_LANGUAGE, contentLanguages, replaceHeader);
}
else {
doAddHeaderValue(HttpHeaders.CONTENT_LANGUAGE, contentLanguages, false);
}
return true;
}
else if (HttpHeaders.SET_COOKIE.equalsIgnoreCase(name)) {