Affects: Spring 5.2.4.RELEASE

Hello,

Despite #22797 and #23775, the ShallowETagHeaderFilter keeps overwriting ETag and Content-Length headers.

Here is a repository with unit tests that feature this issue: https://github.com/mickaeltr/Spring-ShallowEtagHeaderFilter-issue/

@GetMapping("/stream")
public ResponseEntity<InputStreamResource> stream(HttpServletRequest request) {
    // Let's say I have a big input stream for which I want to:
    // - provide the Content-Length and ETag (to avoid a heavy calculation by ShallowEtagHeaderFilter)
    // - allow caching through If-None-Match
    return ResponseEntity.ok()
            .contentType(MediaType.TEXT_PLAIN)
            .eTag("demo") // -> overriden by ShallowETagHeaderFilter
            .contentLength(123) // -> overriden by ShallowETagHeaderFilter
            .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS))
            .body(new InputStreamResource(new ByteArrayInputStream("demo".getBytes())));
}

Thanks

Comment From: rstoyanchev

Thanks for the sample code. It is clear at last, I'm sorry for the back and forth. I'll prepare a fix, and hopefully you can confirm it so we know it's the right fix this time.

Comment From: mickaeltr

That was fast 👏

Comment From: mickaeltr

One of my test was wrong, I fixed it and successfully tested my project against the new ShallowEtagHeaderFilter. Thanks for being so quick (and sorry for not providing sample code earlier).

Comment From: rstoyanchev

There is now a 5.2.5 snapshot to test the fix with.

The tests in the demo project pass with the one exception that I had to change stream_not_modified() to add .header(HttpHeaders.IF_NONE_MATCH, "\"demo\"")) which I think was a test issue.

Comment From: rstoyanchev

Oh I see your comment now :) Thanks for confirming!