Issue Description:
Code in ShallowEtagHeaderFilter
:
WebUtils.getNativeResponse(response, ContentCachingResponseWrapper.class);
should be replaced into
WebUtils.getNativeResponse(response, ConditionalContentCachingResponseWrapper.class);
so that users can implement their own business logic based on ContentCachingResponseWrapper
.
Change ContentCachingResponseWrapper
to ConditionalContentCachingResponseWrapper
so that it gets the right one.
private void updateResponse(HttpServletRequest request, HttpServletResponse response) throws IOException {
ContentCachingResponseWrapper wrapper =
// WebUtils.getNativeResponse(response, ContentCachingResponseWrapper.class);
WebUtils.getNativeResponse(response, ConditionalContentCachingResponseWrapper.class);
Assert.notNull(wrapper, "ContentCachingResponseWrapper not found");
HttpServletResponse rawResponse = (HttpServletResponse) wrapper.getResponse();
if (isEligibleForEtag(request, wrapper, wrapper.getStatus(), wrapper.getContentInputStream())) {
String eTag = wrapper.getHeader(HttpHeaders.ETAG);
if (!StringUtils.hasText(eTag)) {
eTag = generateETagHeaderValue(wrapper.getContentInputStream(), this.writeWeakETag);
rawResponse.setHeader(HttpHeaders.ETAG, eTag);
}
if (new ServletWebRequest(request, rawResponse).checkNotModified(eTag)) {
return;
}
}
wrapper.copyBodyToResponse();
}
I have implemented my own Filter, and in my own Filter, i have implemented my own ResponseWrapper which extends ContentCachingResponseWrapper
, everything works fine if ShallowEtagHeaderFilter
is not loaded, but when it works with ShallowEtagHeaderFilter
, when ShallowEtagHeaderFilter.updateResponse
is invoked, the real HttpServletResponse get through WebUtils.getNativeResponse(response, ContentCachingResponseWrapper.class);
become my own ResponseWrapper, so my own logic will be invoked inside ShallowEtagHeaderFilter
, which is a mistake.
By changing the code to WebUtils.getNativeResponse(response, ConditionalContentCachingResponseWrapper.class);
, everything will be fine.
Affects: \<5.2.5.RELEASE and others>