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-34466
This commit is contained in:
Brian Clozel
2025-02-21 14:23:12 +01:00
parent 01ae0a7c26
commit b5c89c91a9
3 changed files with 24 additions and 2 deletions

View File

@@ -671,7 +671,12 @@ public class MockHttpServletResponse implements HttpServletResponse {
@Override
public void setHeader(String name, @Nullable String value) {
setHeaderValue(name, value);
if (value == null) {
this.headers.remove(name);
}
else {
setHeaderValue(name, value);
}
}
@Override