Reputation: 77
I would like to use server-sent events in an Rails 3.1-project. Server-sent events have to include messages of the mime-type "text/event-stream". So is it possible to take a String for example like:
@message = 'data: {"title": "this is a title"}\n\n'
and render it to a HTTP like that:
EventMachine::HttpRequest.new(URL).post({
:message => render :text/event-stream => @message
})
Would be nice to know if this works or how I should handle it otherwise.
Upvotes: 1
Views: 371
Reputation: 3960
You can also just use a standard action to render your response like so...
response.headers["Cache-Control"] = "no-cache"
render :text => "data:#{Random.rand(0..10000)}\n\n", :content_type => "text/event-stream"
Upvotes: 1