我正在尝试在 Rails 应用程序中发送流式响应,特别是使用 multipart/x-mixed-replace
内容类型。据我所知,Rails 不支持流式响应,因为容器在向客户端发送任何内容之前会尝试缓冲并确定响应正文的长度。
顺便说一句,我们正在使用 Mongrel 部署 Rails 应用程序,看起来像 自定义 Mongrel 处理程序可以很好地传输数据,甚至可以与 Rails 应用程序很好地配合。我已经能够创建一个自定义处理程序,但我不知道如何让它与 Rails 应用程序一起工作。
例如,我希望对 URI /foo.*
的所有请求都转到自定义处理程序,而所有其他请求都由 Rails 处理。有人可以建议如何实现这一点吗?我似乎无法复制上面链接文章的结果。或者是否有更简单的方法让 Rails 处理程序生成开放式流式响应?
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?
发布评论
评论(1)
罪魁祸首是 OS X 上的虚假杂种安装。使用 链接文章 使用如下简单的处理程序:
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: