루비/랙의 멀티 파트 응답
문제
내 서버가 멀티 파트 응답 (multipart/x-mixed-replace)을 보내기를 원합니다. Sinatra 프레임 워크 또는 일반 랙 앱을 사용하여 일종의 솔루션을 선호하지만 Ruby의 예제는 좋을 것입니다. 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
그러나 Mongrel을 사용하여 Ruby 코드를 제공하는 경우 (ROR을 사용하는 많은 사람들과 마찬가지로) 전혀 스트리밍 할 수 없습니다.
제휴하지 않습니다 StackOverflow