Skip to content

Add support for http byte-range requests for non-static resources [SPR-13834] #18407

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 Jan 3, 2016 · 14 comments
Assignees
Labels
has: votes-jira Issues migrated from JIRA with more than 10 votes at the time of import in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 3, 2016

Burkhard Graves opened SPR-13834 and commented

#15431 adds support for http byte-range requests for serving static resources with a ResourceHttpRequestHandler.

It would be nice to have the same for non-static resources (e.g. streaming a video which was uploaded beforehand).

https://gist.github.com/davinkevin/b97e39d7ce89198774b4 shows a solution but it would be nice to have this in spring itself.


Affects: 4.2.4

Reference URL: #754

Issue Links:

Referenced from: commits 582014e, c7bd3b8, 5ac31fb

11 votes, 13 watchers

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jan 4, 2016

Rossen Stoyanchev commented

The HTTP byte range support from #15431 has two parts. One is in HttpHeaders for parsing and representing byte range information and that can be used from any code. The second is an actual use of this in ResourceHttpRequestHandler where you could say it is a built-in feature.

You can already use the foundational support for byte ranges to simplify your code significantly. I'm wondering what more beyond that do you have in mind?

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jan 13, 2016

Burkhard Graves commented

Ok, let's say I have a simple Spring-Boot app.

If there is a big mp4 video src/main/webapp/resources/monty_python.mp4 than
http://localhost:8080/resources/monty_python.mp4 works perfectly thanks to #15431 (incl. jumping forwards/backwards in the video).

But if such a big mp4 video is uploaded and stored in a local file storage beforehand (not under resources), it would be nice if one could simply write

@RequestMapping(method = RequestMethod.GET, value = "/video", produces = "video/mp4")
@ResponseBody
public FileSystemResource video() {
    return new FileSystemResource(new File("[path to filestorage]/monty_python.mp4"));
}

But in this case http://localhost:8080/video is not working (well) due to the missing byte-range support for non-static resources.

(people also asking on stackoverflow e.g. http://stackoverflow.com/questions/28427339/how-to-implement-http-byte-range-requests-in-spring-mvc)

@spring-projects-issues
Copy link
Collaborator Author

Phil Webb commented

I think this change has broken Spring Boot or Mock MVC. I'm seeing an NPE in this build https://build.spring.io/download/BOOT-PUB-JOB1/build_logs/BOOT-PUB-JOB1-3898.log

@spring-projects-issues
Copy link
Collaborator Author

Phil Webb commented

Never mind, we subclass ResourceHttpRequestHandler and use it outside of the application context. Looks like we need to manually call afterPropertiesSet.

@spring-projects-issues
Copy link
Collaborator Author

Phil Webb commented

BTW you're missing a this :)

diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java
index c521913..6069882 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java
@@ -170,7 +170,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
        }
 
        public ResourceHttpMessageConverter getResourceHttpMessageConverter() {
-               return resourceHttpMessageConverter;
+               return this.resourceHttpMessageConverter;
        }

@spring-projects-issues
Copy link
Collaborator Author

Brian Clozel commented

Thanks Phil Webb!

@spring-projects-issues
Copy link
Collaborator Author

Davin Kevin commented

+1 Thanks a lot, thanks to it, I will remove a lot of code from my app !

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented May 2, 2016

Brian Clozel commented

This feature is being reconsidered in #18795.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented May 3, 2016

Brian Clozel commented

While refactoring this feature in #18795, we've found many issues with the design of this implementation.

That's why this feature has been removed as of 4.3.RC2 as part of #18795.
This has been rescheduled to a future release.

Sorry about this!

@spring-projects-issues
Copy link
Collaborator Author

Burkhard Graves commented

Would have been really great to have this in the upcoming 4.3 release! A higher priority would be nice at least...

Anyway, thanks for your efforts!

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Sep 6, 2016

Rossen Stoyanchev commented

Linking in #19228 since this request should be considered on the reactive side as well.

@spring-projects-issues
Copy link
Collaborator Author

Glaucio Melo commented

I've saw a new spring release here, few hours ago: https://github.com/spring-projects/spring-framework/releases/tag/v5.0.0.M3

Does this release is considering this ticket?

Thanks,

GMelo

@spring-projects-issues
Copy link
Collaborator Author

Brian Clozel commented

No, this is targeted for 5.0.0.M4.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Aug 20, 2017

Burkhard Graves commented

I guess this is something we won't see in 5.0 GA, right?

A solution/workaround utilizing the stuff introduced in #15431 can be found here ("A simple solution for handling non-static resources...").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has: votes-jira Issues migrated from JIRA with more than 10 votes at the time of import in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants