-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
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 with custom body type, I'm getting following Parse Error;
Parse Error: The response headers can't include "Content-Length" with chunked encoding
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();
}
}