It is unknown if this breakage still exists. I don’t use SCGI anymore (I use Phusion’s Passenger instead), so this information may be competely irrelevant.

The project I’m working on currently must protect access to some files. They are Flash applications which the user must be authenticated to use.

The best way to do that in Rails is to hide the files in a non-public directory, and then use send_file to stream the file to the browser.

Unfortunately, it seems that using SCGI and Apache breaks #send_file. The following errors are shown in Apache’s error log:

[Mon Dec 26 14:39:47 2005] [error]
[client 69.70.167.187]
malformed header from script. Bad header=FWS\x05\xbf\x97: binary
[Mon Dec 26 14:39:47 2005] [error]
[client 69.70.167.187]
(500)Unknown error: scgi: Unknown error: error reading response headers

(Content reformatted for readability)

I searched the Rails mailing list, and found SCGI error with send_data. No conclusive information in the thread, and Zed has not released another version of SCGI yet.

Just for the heck, I removed the default buffering that #send_file does:

1 send_file request_file, :disposition => 'inline',
2                         :filename => @app.name,
3                         :stream => false

Bingo ! Things started working perfectly fine after that.

Search

Your Host

A picture of me

I am François Beausoleil, a Ruby on Rails and Scala developer. During the day, I work on Seevibes, a platform to measure social interactions related to TV shows. At night, I am interested many things. Read my biography.

Top Tags

Books I read and recommend

Links

Projects I work on

Projects I worked on