Skip to content

Add support for HEAD methods in Spring's Resource handling #28291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hannosgit opened this issue Apr 6, 2022 · 1 comment
Closed

Add support for HEAD methods in Spring's Resource handling #28291

hannosgit opened this issue Apr 6, 2022 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@hannosgit
Copy link

hannosgit commented Apr 6, 2022

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).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 6, 2022
@poutsma poutsma self-assigned this Apr 7, 2022
@poutsma poutsma added in: web Issues in web modules (web, webmvc, webflux, websocket) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 7, 2022
@poutsma poutsma added this to the 6.0.0-M4 milestone Apr 7, 2022
@poutsma poutsma added the type: enhancement A general enhancement label Apr 7, 2022
@poutsma
Copy link
Contributor

poutsma commented Apr 7, 2022

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.

@poutsma poutsma changed the title Spring Web ResourceHandler HEAD method for large files is slow Add support for HEAD methods in Spring's Resource handling Apr 7, 2022
@poutsma poutsma closed this as completed in 9adfa5e Apr 7, 2022
poutsma added a commit that referenced this issue Apr 12, 2022
This commit fixes a regression that added the Accept-Ranges header on
both client and server. Accept-Ranges is response header, so we now make
sure it only appears on the server side.

See gh-28291
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants