schacon/grack — Issue #13: X-Sendfile and X-Accel-Redirect support
Author: brodock
Created: 2012-02-09 05:00:01+00:00
State: open

While Ruby/Rack is fine to be an intermediary to handle permission/authentication, it's not the best tool at reading/sending files. A better solution can be to delegate it to the webserver (Apache2/Nginx), with X-Sendfile and X-Accel-Redirect HTTP responses.

You can read more about then here:

http://wiki.nginx.org/XSendfile
https://tn123.org/mod_xsendfile/

All you have to do is craft a HTTP response code with one of the two (configurable) and append the path for the file resource and let the webserver handle the file transmission.