Multipart response in Ruby/Rack

前端 未结 1 1472
无人共我
无人共我 2021-01-06 17:33

I want my server to send a multipart response (multipart/x-mixed-replace). I\'d prefer some kind of solution using the Sinatra framework or a generic Rack app, but any examp

1条回答
  •  离开以前
    2021-01-06 17:44

    You can probably use the out.flush method for this:

    class TestController < ApplicationController
      def index
        render :text => lambda { |resp, out|
          out.puts 'start'
          out.flush
          10.times do
            out.puts '.'
            out.flush
            sleep 1
          end
          out.puts 'done'
        }
      end
    end
    

    However, keep in mind that if you're using Mongrel to serve your Ruby code (as many people using RoR do), you won't be able to stream at all.

    0 讨论(0)
提交回复
热议问题