Created
May 29, 2013 16:21
-
-
Save geku/5671589 to your computer and use it in GitHub Desktop.
Streaming example with CURB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra/base' | |
server = Thread.new do | |
class Example < Sinatra::Base | |
set :server, :thin | |
get '/' do | |
stream(:keep_open) do |out| | |
5.times { | |
out << "streaming output\n" | |
sleep 1 | |
} | |
out.close | |
end | |
end | |
run! | |
end | |
end | |
sleep 2 | |
# CURB client | |
require 'curb' | |
curl = Curl::Easy.new | |
curl.url = 'http://localhost:4567/' | |
curl.on_body do |data| | |
puts ">> #{data}"; data.size | |
end | |
curl.http(:GET) | |
server.exit |
Yes I'm interested in every single line as soon as it arrives. My use case is basically a long running server process that streams e.g. log output.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That works with Typhoeus out of the box:
Edit: oh. You don't see the single lines... do you need that? Ethon might me be suited then...