我希望我的服务器发送一个多部分响应(多部分/ X - 混合替换)。我宁愿某种使用西纳特拉框架或通用机架应用的解决方案,但在红宝石任何例子就好了。下面是我想要做等值,在PHP中:

<?php
  header('Content-type: multipart/x-mixed-replace;boundary="rn9012"');

  print "--rn9012\n";
  print "Content-type: application/xml\n\n";
  print "<?xml version='1.0'?>\n";
  print "<content>First Part</content>\n";
  print "--rn9012\n";
  flush();

  sleep(5);
  print "Content-type: application/xml\n\n";
  print "<?xml version='1.0'?>\n";
  print "<content>Second Part</content>\n";
  print "--rn9012--\n";

?>
有帮助吗?

解决方案

可以大概使用了out.flush方法这样:

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

但是,请记住,如果您使用的杂种狗,以满足您的Ruby代码(尽可能多的人使用回报率做),你将无法在所有的流。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top