У меня проблема с функцией прямой трансляции. Мой контроллер:
class SseTestsController < ApplicationController
include ActionController::Live
def test1
response.headers['Content-Type'] = 'text/event-stream'
3.times {
puts "writing data to the stream..."
response.stream.write "hello world"
sleep 1
}
puts "closing stream..."
response.stream.close
puts "closed"
end
Маршрут:
get 'sse' => 'sse_tests#test1'
Когда я делаю запрос к /sse
, ничего не происходит. Никакие данные не отправляются клиенту, хотя рельсы говорят:
Processing by SseTestsController#test1 as */*
writing data to the stream...
writing data to the stream...
writing data to the stream...
closing stream...
closed
Completed 200 OK in 3008ms (ActiveRecord: 0.0ms)
В wireshark я вижу только сам запрос, но без каких-либо данных, отправленных обратно клиенту:
GET /sse HTTP/1.1
User-Agent: curl/7.40.0
Host: localhost:3000
Accept: */*
и curl зависает в ожидании ответа (как и браузер), приложение rails зависает и не обрабатывает другие запросы. Абсолютно ничего не происходит.
я использую сервер пумы
bundle exec rails server -b 0.0.0.0
=> Booting Puma
=> Rails 4.2.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Puma 2.11.1 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://0.0.0.0:3000
Started GET "/sse" for 127.0.0.1 at 2015-03-10 16:31:13 +0200
ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by SseTestsController#test1 as */*
writing data to the stream...
writing data to the stream...
writing data to the stream...
closing stream...
closed
Completed 200 OK in 3007ms (ActiveRecord: 0.0ms)
Я старался
config.preload_frameworks = true
config.allow_concurrency = true
в config/enviroments/development.rb
, но это не помогло.
Рельсы 4.2.0, Руби 2.0.0p247
ensure
захотеть закрыть стрим. - person kobaltz   schedule 10.03.2015