[WEBrick] streaming output

Is there a way to send a stream of output while processing, I want to send ongoing status? The basic response construct seems to want the output in a finalized form. The clients will render progressively from what I understand.

Dan

In message <812ABBE6-4255-11D9-AF7F-00039357B54C@3skel.com>,

Is there a way to send a stream of output while processing, I want to
send ongoing status? The basic response construct seems to want the
output in a finalized form. The clients will render progressively from
what I understand.

Set an IO to res.body, and write data from another thread.

require "webrick"

class Streamlet < WEBrick::HTTPServlet::AbstractServlet
  def do_GET(req, res)
    res["content-type"] = "application/octet-stream"
    r, w = IO.pipe
    res.body = r
    Thread.start{
      10.times{|i|
        w.write("#{i}" * 4096)
        sleep(1)
      }
      w.close
    }
  end
end

httpd = WEBrick::HTTPServer.new(:Port=>10080)
httpd.mount("/", Streamlet)
trap(:INT){ httpd.shutdown }
httpd.start

ยทยทยท

`Dan Janowski <danj@3skel.com>' wrote:

--
gotoyuzo