HTTP Streaming Ruby Client
Let's say you have a HTTP streaming server such as the one below where the server sends the HTTP response slowly or may it even holds on the request and does not close the connection and keep sending data (so called "HTTP Streaming"). How would you write a client that receives the response segments as soon as they arrive? (we do not want to wait till the whole response ends or we do not have a choice since the server is streaming "infinite" data). require 'rubygems' require 'mongrel' class StreamHandler def process(request, response) response.status = 200 response.send_status(nil) response.header['Content-Type'] = "text/plain" response.send_header 10.times do response.write("Message \r\n") sleep 5 end response.done end end Mongrel::Configurator.new do listener :port => 3000 do uri "/", :handler => StreamHandler.new end run; join end The client code...