I am working on adding a streaming component to my rails application since I would like to start using SSE. I tried to get this to work in a smaller example, but I still have problems. I am having trouble getting rails in order to correctly send a response to a curl request. I follow the tutorial at http://tenderlovemaking.com/2012/07/30/is-it-live.html . I am not sure if there is something that I need to configure for OSX, or if something is missing in my configuration. Any help would be greatly appreciated.
I am running this locally on OSX. When I run curl -i localhost:3000, I get the following response:
HTTP/1.1 200 OK
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-UA-Compatible: chrome=1
Content-Type: text/event-stream
Last-Modified: Wed Apr 23 23:10:15 2014
Cache-Control: no-cache
Set-Cookie: request_method=GET; path=/
X-Request-Id: 89f2af3e-76e9-4873-85b0-3b6fe45f6343
X-Runtime: 0.001724
Transfer-Encoding: chunked
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
, , , . , , .
:
stream_test_controller.rb
class StreamTestController < ActionController::Base
include ActionController::Live
def index
response.headers['Content-Type'] = 'text/event-stream'
10.times {
logger.info "hello world sent"
response.stream.write "hello world\n"
sleep 1
}
response.stream.close
end
end
Gemfile
source 'https://rubygems.org'
ruby '2.1.0'
gem 'rails', '4.0.3'
gem 'sqlite3'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
gem 'puma'
group :doc do
gem 'sdoc', require: false
end
development.rb
StreamTest::Application.configure do
config.preload_frameworks = true
config.allow_concurrency = true
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = true
end