【问题标题】:Rails 3.1 - rendering an individual mime-type to a http-requestRails 3.1 - 将单个 mime 类型呈现为 http-request
【发布时间】:2011-11-18 07:21:10
【问题描述】:

我想在 Rails 3.1 项目中使用服务器发送的事件。服务器发送的事件必须包含 mime 类型“文本/事件流”的消息。那么是否可以使用一个字符串,例如:

@message = 'data: {"title": "this is a title"}\n\n' 

并像这样将其呈现给 HTTP:

EventMachine::HttpRequest.new(URL).post({
  :message => render :text/event-stream => @message 
})

很高兴知道这是否有效或者我应该如何处理它。

【问题讨论】:

  • @james_schorr 我更新了问题。经过一晚上的思考和睡眠后,我认为渲染可能是解决我想做的事情的正确方法。
  • 在我看来它会起作用的。

标签: ruby-on-rails ruby-on-rails-3.1 mime-types


【解决方案1】:

您也可以像这样使用标准操作来呈现您的响应...

response.headers["Cache-Control"] = "no-cache"
render :text => "data:#{Random.rand(0..10000)}\n\n", :content_type => "text/event-stream"

【讨论】:

  • 对不起,我没有回复你的答案,但我已经放弃了这个项目......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-23
  • 2011-12-22
  • 2014-05-27
相关资源
最近更新 更多