[Mongrel] Streaming content

Ry Dahl ry at tinyclouds.org
Sun Mar 25 20:57:54 EDT 2007


Hello

I'm attempting to write a mongrel plug-in which would stream a response.

At first I was doing this

  def process(request, response)
    response.start do |head,out|
      head['Content-Type'] = 'text/html'
      %w{o m g}.each { |c|  out.puts c; sleep 5; }
    end
    response.done = true
  end

But then I looked at HttpResponse and decided that this probably isn't
sending anything to the socket while I'm in the OMG loop:

    def start(status=200, finalize=false)
      @status = status.to_i
      yield @header, @body
      finished if finalize
    end

So I thought using HttpResponse#write might work -

  def process(request, response)
    %w{o m g}.each { |c| response.write(c); sleep 5; }
    response.done = true
  end

but that also didn't work. How can I stream content?

THANKS!


More information about the Mongrel-users mailing list