I am making a simple rack that provides access to protected files after authentication.
Since the data in the files is sensitive, they are located in the non-public folder of the application.
Now, after checking the session data, I just open the file to read and send the contents as the response body.
It feels ugly and must consume resources for large files very much.
Answer example:
[ "200", {"Content-Type"=> MIME::Types.type_for(file).first.to_s }, File.open( file ).read() ]
I looked at Rack :: Sendfile , but as far as I understand, it is middleware and cannot send files from the application by itself.
What would be the most efficient way to send non-public binaries from a Rack app?
source share