Created
May 5, 2011 22:22
-
-
Save nicksieger/958096 to your computer and use it in GitHub Desktop.
X-Sendfile middleware for JRuby-Rack 1.0.8 or greater
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JRubyRackXSendfile | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
result, headers, body = @app.call(env) | |
if headers['X-Sendfile'] | |
[result, headers, File.new(headers.delete('X-Sendfile'))] | |
else | |
[result, headers, body] | |
end | |
end | |
end |
...make sure the controller sets the header when sending a file so this middleware picks it up.
To clarify, for example:
module ApplicationHelper
def set_sendfile_header(path_to_file)
request.headers['X-Sendfile'] = path_to_file.to_s
end
end
class MyController < ApplicationController
def download
set_sendfile_header params[:file]
end
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/questions/5904693/sendfile-on-jruby-jrack-tomcat