Fix null value support in ContentCachingResponseWrapper
Prior to this commit, calling `setHeader` on the response wrapper would have a separate code path for the "Content-Length" header. This did not support calls with `null` values and would result in an exception. This commit ensures that the cached content length value is reset in this case and that the call is forwarded properly to the superclass. Fixes gh-34460
This commit is contained in:
@@ -270,6 +270,17 @@ class ContentCachingResponseWrapperTests {
|
||||
.withMessageContaining(overflow);
|
||||
}
|
||||
|
||||
@Test
|
||||
void setContentLengthNull() {
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response);
|
||||
responseWrapper.setContentLength(1024);
|
||||
responseWrapper.setHeader(CONTENT_LENGTH, null);
|
||||
|
||||
assertThat(response.getHeaderNames()).doesNotContain(CONTENT_LENGTH);
|
||||
assertThat(responseWrapper.getHeader(CONTENT_LENGTH)).isNull();
|
||||
}
|
||||
|
||||
|
||||
private void assertHeader(HttpServletResponse response, String header, int value) {
|
||||
assertHeader(response, header, Integer.toString(value));
|
||||
|
||||
Reference in New Issue
Block a user