[Mongrel] Rails' send_file, Mongrel, and *gasp* memory

Steven Hansen runner at berkeley.edu
Fri Dec 22 09:03:29 EST 2006


Hi Jon,

I don't know much about mod_secdownload, but I do know that both 
apache2.x.x and lighttpd can use the X-Sendfile header.

See: http://celebnamer.celebworld.ws/stuff/mod_xsendfile/

I have an Apache -> Mongrel setup where I've installed mod_xsendfile for 
apache.   When you want to send a file to the user
simply do something like:

    response.headers['Content-Type'] = "application/force-download"
    response.headers['Content-Disposition'] = "attachment; 
filename=\"#{file.short_name}\""
    response.headers["X-Sendfile"] = file.name
    response.headers['Content-length'] = file.size_in_bytes

apache will then step in and serve the file.

Regards,
Steven


Jonathan Leighton wrote:
> On Fri, 2006-12-22 at 00:06 -0800, Zed A. Shaw wrote:
>   
>>> To be clear, send_file does not read the whole file into memory -- it blows
>>> chunks into the output stream. Mongrel and pure-Ruby FastCGI use StringIO to
>>> buffer the response before sending it to the client.
>>>
>>> X-Sendfile is definitely the way to go in any case.
>>>       
>> Just to be extra clear, neither of the two main systems for hosting Rails would need to buffer the output if Rails didn't alternate between sending headers and body content.
>>
>> And yes, X-Sendfile is the way to go.
>>     
>
> Thanks for all your responses. Just in case it makes a difference, I'll
> clarify about my setup. Basically we have an Apache on port 80 which
> can't be removed from the equation. The Rails app is served directly
> Apache -> Mongrel, and now I have made it so the /file/ path is proxied
> Apache -> lighttpd, which serves the files using mod_secdownload. I
> wasn't actually aware of X-Sendfile so that's interesting -- is this
> better, worse or equal to using mod_secdownload? I wouldn't have thought
> it made a difference as they both enable lighttpd to serve the static
> files, but if people think I should drop the mod_secdownload solution in
> favour of X-Sendfile I guess I could set up the application to go
> through lighttpd too.
>
> Thanks again,
>
> Jon
>
> _______________________________________________
> Mongrel-users mailing list
> Mongrel-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mongrel-users
>   



More information about the Mongrel-users mailing list