views:

28

answers:

1

I'm trying to send a streaming response in a Rails application, specifically using the multipart/x-mixed-replace content type. As far as I can tell, streaming responses are not supported by Rails since the container tries to buffer and determine the length of the response body before sending anything to the client.

Incidentally, we are deploying our Rails app with Mongrel, and it seems like custom Mongrel handlers can stream data fine and even play nice with Rails apps. I've been able to create a custom handler but I can't figure out how to get it to work along-side the Rails app.

For example, I would like all requests to the URI /foo.* to go the custom handler and all others to be handled by Rails. Can someone advise how to make this happen? I can't seem to replicate the results from the linked article above. Or is there an easier way to get a Rails handler to produce an open-ended, streaming response?

A: 

The culprit was a bogus mongrel install on OS X. A proper install works fine using guidance from the linked article using a simple handler like below:

# foo_handler.rb
class FooHandler < Mongrel::HttpHandler
  # def process(req, res); streaming_impl; end 
end
# Usage: mongrel_handler start -S foo_handler.rb
uri "/foo", :handler => FooHandler.new
maerics