Affects: Spring Web 5.3.18 Tested with: Tomcat and Jetty Tested with: Linux and Windows


I want to download large files (>10GB) from a Spring Web Server, before I start the download I want to know the size of the remote file, so, therefore, I make a HEAD request on the remote file.

Static files are served via ResourceHandlers, eg.

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry
            .addResourceHandler("/**")
            .addResourceLocations("file:download/");
    }

}

and then when I make a HEAD request on a large file (> 10 GB), on the first try I get the response within milliseconds but when I try again the response takes seconds ( >10s).

Comment From: poutsma

The underlying reason for this is that resource handling in Spring MVC (and WebFlux) does not have explicit support for HEAD methods yet. Instead, we treat the request as a GET, write the entire file to the body, and rely on the standard HttpServlet::doHead functionality to ignore everything written.

I will introduce HEAD support in ResourceHttpRequestHandler and ResourceWebHandler.