Rails3, Apache Passenger and empty file using send file
One of the types of response in web applications is to send file contents to the client.
In Rails the task is vary simple to accomplish. You can use send_file method to send the given file to the client. The method sets the Content-Length, Content-Type, Content-Disposition, and Content-Transfer-Encoding headers. Super easy!
Unfortunately if use Rails3 and your application is deployed on Apache Passenger send_file method will stop working.
This is due to X-Sendfile header that is by default set in Rails 3.
In general this is very useful feature that helps to offload streaming download to front server by returning empty response with X-Sendfile header with path.
If a performance is not a priority for you …you can solve the issue in 10 seconds by commenting out…
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
…in production.rb file …or you can invest 15 minutes of your time and try to install mod_xsendfile module on your Apache.

Comments