Fix ServletResponseHttpHeaders#get null handling

ServletResponseHttpHeaders#get should be annotated with `@Nullable` and
return null instead of a singleton list containing null when there is no
content type header.

Closes gh-32362
This commit is contained in:
Sébastien Deleuze
2024-03-04 14:25:51 +01:00
parent ce9dc19a3c
commit 7493ce86b6
2 changed files with 16 additions and 1 deletions

View File

@@ -75,6 +75,19 @@ class ServletServerHttpResponseTests {
assertThat(mockResponse.getCharacterEncoding()).as("Invalid Content-Type").isEqualTo("UTF-8");
}
@Test
void getHeadersWithNoContentType() {
this.response = new ServletServerHttpResponse(this.mockResponse);
assertThat(this.response.getHeaders().get(HttpHeaders.CONTENT_TYPE)).isNull();
}
@Test
void getHeadersWithContentType() {
this.mockResponse.setContentType(MediaType.TEXT_PLAIN_VALUE);
this.response = new ServletServerHttpResponse(this.mockResponse);
assertThat(this.response.getHeaders().get(HttpHeaders.CONTENT_TYPE)).containsExactly(MediaType.TEXT_PLAIN_VALUE);
}
@Test
void preExistingHeadersFromHttpServletResponse() {
String headerName = "Access-Control-Allow-Origin";