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
Easy file streaming #281
Comments
Sounds good to me. I believe SimpleBridge has built-in facilities for sending files that should be easy to hook into. The webserver (Cowboy etc) will handle the chunk sizing, though in practice it will just use sendfile. The webserver should also handle encoding and conditional requests. BTW the content-type "application/octet-stream" is standard when the file type is not recognized. I am not sure what Cowboy does when it encounters a read error; either 500 or 40X would be sensible. If you want to take a crack at this check out how CB delivers files from the static directory: https://github.com/evanmiller/ChicagoBoss/blob/master/src/boss/boss_web_controller.erl#L430 |
This commit adds (buggy) support for streaming a static file directly from a controller. Three known problems: - the status code is not indicated properly, as simple_bridge passes this off to the web server - hard to know where the docroot is for relative pathnames - doesn't seem to support absolute file paths Still, it's a start.
The commit looks like a good start. I am not 100% certain but I think the absolute pathname issue is a security "feature" of either SimpleBridge or the web server. As for relative paths I think the only sane thing to do is make them relative to priv/static. What do you mean "the status code is not indicated properly"? No 304s? |
My 2 cents
IMO this is wrong. this would make these files public for all. priv/static files are usually served directly by nginx. |
That makes sense. I am wondering if this should be configurable so you could define a directory outside the application, which would be desirable if you have multiple applications or services involved in file creation. I hadn't thought about deleting but that also makes sense for temporary files. |
Configurable with some sane defaults, like priv/files/ or even /tmp |
I would like to hand the details of streaming files to the client off to the framework. If I could return a file path, Chicago Boss should know what to do.
Here are some proposed controller return values:
Some worthwhile features:
Accept-Encoding
preferencesLastModified
values500 errors could be generated in the following cases:
undetectable_content_type
- system could not determine what theContent-Type
to declare the file isSome added
The text was updated successfully, but these errors were encountered: