Skip to content

Add support for http byte-range requests [SPR-10805] #15431

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
spring-projects-issues opened this issue Aug 5, 2013 · 10 comments
Closed

Add support for http byte-range requests [SPR-10805] #15431

spring-projects-issues opened this issue Aug 5, 2013 · 10 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Aug 5, 2013

Nicolas Pottrain opened SPR-10805 and commented

Is it possible to add support for byte-range requests in the mvc:resources ResourceHttpRequestHandler.
This will enable the serving of video files to iOS devices and for Safari on Mac.


Affects: 3.2.3

Reference URL: http://forum.springsource.org/showthread.php?114763-HTTP-byte-range-requests-for-resources-in-Spring-MVC

Issue Links:

3 votes, 12 watchers

@spring-projects-issues
Copy link
Collaborator Author

Thomas Meyer commented

This post seems related, I haven't tried it though: http://datum-bits.blogspot.fr/2013/01/implementing-http-byte-range-requests_30.html

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

Are you running on Tomcat? It looks like the DefaultServlet there supports byte-range requests. In which case it might be simply be a matter of enabling default service handling in your Spring MVC config. When the ResourceHttpRequestHandler can't find a resource it forwarded to the container's "default" servlet.

More generally speaking the ResourceHttpRequestHandler was designed for serving application resources (css, js, images, etc) and is not optimized for serving large files (like videos) which is what byte-ranges would be most attractive. So if we added such support it would almost have to along with more optimal IO (e.g. file mapped byte buffer) to support the use case fully.

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

PR at #754

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

This is now available in the master branch (4.2.0.BUILD-SNAPSHOT). Nicolas Pottrain it would be very good if you could verify it works for you. Thanks!

@spring-projects-issues
Copy link
Collaborator Author

Andrei Holub commented

I have some issues in Chrome after this feature was added. Is it any way to manually disable it?

@spring-projects-issues
Copy link
Collaborator Author

Kevin McLaughlin commented

We ended up adding a servlet filter that drops attempts to set ACCEPT_RANGE header.

Sample bootapp showing this issue is at https://github.com/krm1312/springrangeissues. Take that project and:

mvn clean package && java -jar bootapp/target/bootapp.jar

and then try a range request with curl:

curl -vvv -H "Accept-Encoding: gzip"  -H 'Range: bytes=4726785-5726784' http://localhost:8080/test/file.bin > /tmp/f

It effectively hangs.

@spring-projects-issues
Copy link
Collaborator Author

Kevin McLaughlin commented

If anybody else runs into this issue...

Just removing Accept-Range didn't work. RFC says browsers may send a range request anyway. Now we're setting Accept-Range: none in the filter and hiding any incoming Range header (by wrapping the request and overriding getHeader). Basically, try to tell the browser we don't support range requests and even if the browser sends a range request, ignore it and serve up a 200 with full content.

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

Andrei Holub, would you mind creating a new ticket to describe the issue with Chrome you're running into? We can add a way to disable it but would like to get some more details.

Kevin McLaughlin, it sounds like your issue is with actually trying to use byte ranges without success? Would you mind also creating a new ticket? We'll take a look.

This ticket is for the original request and is already closed and will not be re-opened.

Thanks!

@spring-projects-issues
Copy link
Collaborator Author

Kevin McLaughlin commented

Andrei and I are colleagues, so, describing the same incident/app. Will open two new tickets though - one to allow disabling and one to investigate/fix the issue when enabled.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 9, 2015

Kevin McLaughlin commented

#18236
#18235

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

2 participants