Handle null values in MockHttpServletResponse#setHeader

Prior to this commit, `MockHttpServletResponse#setHeader` would not
remove the header entry when given a `null` value, as documented in the
Servlet API.
This commit ensures that this behavior is enforced.

Fixes gh-34464
This commit is contained in:
Brian Clozel
2025-02-21 14:23:12 +01:00
parent 4606337180
commit 6dd73ae3e4
3 changed files with 24 additions and 2 deletions

View File

@@ -88,6 +88,18 @@ class MockHttpServletResponseTests {
assertThat(response.containsHeader(headerName)).isFalse();
}
@ParameterizedTest
@ValueSource(strings = {
CONTENT_TYPE,
CONTENT_LANGUAGE,
"X-Test-Header"
})
void removeHeaderIfNullValue(String headerName) {
response.addHeader(headerName, "test");
response.setHeader(headerName, null);
assertThat(response.containsHeader(headerName)).isFalse();
}
@Test // gh-26493
void setLocaleWithNullValue() {
assertThat(response.getLocale()).isEqualTo(Locale.getDefault());