I'm trying to leverage Server-Sent Events in my application. I am using Sinatra and the sinatra-sse
gem. This gem wraps the Sinatra stream :keep_alive
call.
When running my application on Thin, I have absolutely no problems, and my event stream works as expected. However, when I switched my application to run with Puma everything works, except my sse_stream
does absolutely nothing! It just returns a blank page.
My stream is set up like so
get "/logstream/:server" do
if rbcserver = MyApp.servers[params[:server]]
sse_stream do |stream|
rbcserver.add_web_logger(stream)
stream.callback { rbcserver.remove_web_logger(stream) }
end
else
error 404
end
end
I'm starting Thin like so:
@@puma_instance = Puma::Server.new MyApp::WebUI
@@puma_instance.add_tcp_listener ip, port
@@puma_instance.run
Any idea what's going on? Any help would be appreciated.
EDIT: some more info This is what cURL gives when running on Puma
$ curl -L -b cookies.txt -c cookies.txt -i http://localhost:9001/logstream/myserver
HTTP/1.1 200 OK
Content-Type: text/event-stream;charset=utf-8
X-Content-Type-Options: nosniff
Transfer-Encoding: chunked
$
Whereas this is what happens on Thin
$ curl -L -b cookies.txt -c cookies.txt -i http://localhost:9001/logstream/myserver
HTTP/1.1 200 OK
Content-Type: text/event-stream;charset=utf-8
X-Content-Type-Options: nosniff
Connection: close
Server: thin 1.5.1 codename Straight Razor
event: <event name>
data: <my data>
event: <event name>
data: <my data>
<continues as more data comes in>
EDIT: I should add that my application uses EventMachine at its core, so sinatra_sse
's coupling to EM is most likely not an issue.