Honor Content-[Type|Length] headers from wrapped response again
Commit 375e0e6827 introduced a regression in
ContentCachingResponseWrapper (CCRW). Specifically, CCRW no longer
honors Content-Type and Content-Length headers that have been set in
the wrapped response and now incorrectly returns null for those header
values if they have not been set directly in the CCRW.
This commit fixes this regression as follows.
- The Content-Type and Content-Length headers set in the wrapped
response are honored in getContentType(), containsHeader(),
getHeader(), and getHeaders() unless those headers have been set
directly in the CCRW.
- In copyBodyToResponse(), the Content-Type in the wrapped response is
only overridden if the Content-Type has been set directly in the CCRW.
Furthermore, prior to this commit, getHeaderNames() returned duplicates
for the Content-Type and Content-Length headers if they were set in the
wrapped response as well as in CCRW.
This commit fixes that by returning a unique set from getHeaderNames().
This commit also updates ContentCachingResponseWrapperTests to verify
the expected behavior for Content-Type and Content-Length headers that
are set in the wrapped response as well as in CCRW.
See gh-32039
See gh-32317
Closes gh-32322
@ -160,16 +161,19 @@ public class ContentCachingResponseWrapper extends HttpServletResponseWrapper {
@@ -160,16 +161,19 @@ public class ContentCachingResponseWrapper extends HttpServletResponseWrapper {
@ -225,10 +229,10 @@ public class ContentCachingResponseWrapper extends HttpServletResponseWrapper {
@@ -225,10 +229,10 @@ public class ContentCachingResponseWrapper extends HttpServletResponseWrapper {
@ -238,12 +242,11 @@ public class ContentCachingResponseWrapper extends HttpServletResponseWrapper {
@@ -238,12 +242,11 @@ public class ContentCachingResponseWrapper extends HttpServletResponseWrapper {
@ -254,7 +257,7 @@ public class ContentCachingResponseWrapper extends HttpServletResponseWrapper {
@@ -254,7 +257,7 @@ public class ContentCachingResponseWrapper extends HttpServletResponseWrapper {
@ -342,7 +345,7 @@ public class ContentCachingResponseWrapper extends HttpServletResponseWrapper {
@@ -342,7 +345,7 @@ public class ContentCachingResponseWrapper extends HttpServletResponseWrapper {