Affects: \<4.3.21>
I'm using ContentCachingResponseWrapper to read response information in a inherited OncePerRequestFilter.doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
level.
At the end I'm calling ContentCachingResponseWrapper.copyBodyToResponse() to copy response body.
When my API returns ResponseEntity
This happens when I use Spring Cloud OpenFeign web client to do the API call. So in the OpenFeign GET response includes "transfer-encoding" in the headers and then when I call ContentCachingResponseWrapper.copyBodyToResponse() it is adding "Content-Length" to the headers.
My code is as follows;
OncePerRequestFilter overriden method;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException
{
ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper(request);
ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response);
try
{
if (ocpHttpTraceService.isLoggingPropertyEnabled(TracingConstants.BODY, TraceType.INBOUND))
{
filterChain.doFilter(requestWrapper, responseWrapper);
}
else
{
filterChain.doFilter(request, response);
}
System.out.println(getRequestBody(requestWrapper));
System.out.println(getResponseBody(responseWrapper));
}
finally
{
responseWrapper.copyBodyToResponse();
}
}
Comment From: rstoyanchev
We can improve this to ensure Content-Length
is not added if Transfer-Encoding
is "chunked".
Comment From: rstoyanchev
By the way you should try and be on at least the latest 4.3.x release which at this point is 4.3.29. I'm wondering also if you have any plans to upgrade to a 5.x release? I think this is reasonably safe to backport but nevertheless I'd rather minimize any potential for unintended impact.
Comment From: KasunAbey
Hi @rstoyanchev , For the moment we don't have any plans to upgrade to 5.x. Please backport if possible to 4.3.29. We will use it. Thanks
Comment From: rstoyanchev
I'll backport to 4.3.x but the fix depends on the ability to get a header from the response which will work only in a Servlet 3+ environment.
Comment From: KasunAbey
Noted, thanks !