Skip to content

ShallowETagHeaderFilter (still) overwrites ETag and Content-Length #24635

@mickaeltr

Description

@mickaeltr

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

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions