Buffering in WEBrick

I'm writing a web application with WEBrick that occasionally has to
send large streams of data to the browser. However, WEBrick seems to
be storing all of the content and then sending it to the user all at
once. Is there any way I could periodically flush WEBrick's output so
the user doesn't have to stare at a blank screen while the server is
working?

Bill Atkins

Hi, sorry for late reply.

In message <e6056acc.0407141125.5d1070ad@posting.google.com>,

I'm writing a web application with WEBrick that occasionally has to
send large streams of data to the browser. However, WEBrick seems to
be storing all of the content and then sending it to the user all at
once. Is there any way I could periodically flush WEBrick's output so
the user doesn't have to stare at a blank screen while the server is
working?

If the body of response is IO, its output will be flushed
with every reading of 4096 bytes chunk.

  require "webrick"

  class Streamlet < WEBrick::HTTPServlet::AbstractServlet
    def do_GET(req, res)
      res["content-type"] = "text/plain"
      reader, writer = IO.pipe
      Thread.start{
        10000.times{|i|
          puts i
          writer << "a" * 1000
          writer << "\n"
        }
        writer.close
      }
      res.body = reader
    end
  end

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

regards,

ยทยทยท

`dejaspam@batkins.com (Bill Atkins)' wrote:

--
gotoyuzo