postrank-labs / goliath

Goliath is a non-blocking Ruby web server framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

streaming examples doesn't work as expected

papayaah opened this issue · comments

Correct me if i'm wrong, but i ran the stream and chunked streaming examples - https://github.com/postrank-labs/goliath/blob/master/examples/stream.rb

I would expect that when i go to http://localhost:9000 on my web browser, i would expect to see the index show up every 1 second and incremented but instead they all flushed at the end of the page load.

Is that how it's really suppose to work?

Yep, the browser will likely buffer the chunked response. If you want a clean server > client-side API, take a look at implementing an SSE endpoint. For a quick intro: http://www.igvita.com/2011/08/26/server-sent-event-notifications-with-html5/

may I ask - why is Sinatra's streaming api / example works as expected - https://github.com/sinatra/sinatra/blob/master/examples/stream.ru

if the issue lies on the browser?

Not familiar with Sinatra's plumbing. Take a look at what the "<<" operator actually does in its internals.. it may be using chunked encoding.

a) open a raw socket connection (e.g. telnet) to your Goliath server and give it a try..
b) try chunked streaming: https://github.com/postrank-labs/goliath/blob/master/examples/chunked_streaming.rb