ShallowEtagHeaderFilter throws a NumberFormatException for responses bigger than 2Gb #33256
Closed
Description
Affects: spring-web 6.1.10
Hello, we're observing an issue with ShallowEtagHeaderFilter when the downloaded file is bigger than 2Gb, the ContentCachingResponseWrapper throws a NumberFormatException due to int overflow when trying to save the Content-Length value.
Is it possible to update this class to support long
values for the Content-Length value?
Here is a stack trace of an exception
java.lang.NumberFormatException: For input string: "2148532224"
at java.base/java.lang.NumberFormatException.forInputString(Unknown Source)
at java.base/java.lang.Integer.parseInt(Unknown Source)
at java.base/java.lang.Integer.valueOf(Unknown Source)
at org.springframework.web.util.ContentCachingResponseWrapper.addHeader(ContentCachingResponseWrapper.java:173)
at jakarta.servlet.http.HttpServletResponseWrapper.addHeader(HttpServletResponseWrapper.java:141)
.......
// Configuration.java
@Bean
public ShallowEtagHeaderFilter shallowEtagHeaderFilter() {
return new ShallowEtagHeaderFilter();
}
and the sample code we use in @RestController
// Controller.java
return ResponseEntity.ok()
.eTag(file.getEtag())
.contentLength(file.getLength()) // long
.header(HttpHeaders.CONTENT_TYPE, file.getContentType())
.build();
It would be great If you could share suggestions on how to avoid this issue when content length overflows int
.