Stream HTTP response

"Mark Kornfilt" <[email protected]> Tue, 14 Aug 2007 18:09:40 -0400
Newsgroups gmane.comp.apache.mod-ruby
Message-ID <[email protected]>
------=_Part_74598_7300691.1187129380245
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi,

I am trying to stream an HTTP response.

The code appended at the end of this mail is an example of what I am trying
to do. It should write to the socket every second. Instead of that, it seems
to buffer the response and write only when it has the entire content.

Can anybody help on this?

Thanks,

Mark


#!/usr/local/bin/eruby
<%
require 'socket'
require 'net/http'
require 'cgi'

cgi = CGI.new

cgi.header("type" => "text/html")

begin
for index in (1 .. 10)
        cgi.print(index.to_s + ":" +  Time.new.to_s + "<br/>")
        sleep(1)
end
rescue StandardError => error
        print "Error running script: " + error
end
%>

------=_Part_74598_7300691.1187129380245
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi, <br><br>I am trying to stream an HTTP response.<br><br>The code appended at the end of this mail is an example of what I am trying to do. It should write to the socket every second. Instead of that, it seems to buffer the response and write only when it has the entire content. 
<br><br>Can anybody help on this?<br><br>Thanks,<br><br>Mark<br><br><br>#!/usr/local/bin/eruby<br>&lt;%<br>require &#39;socket&#39;<br>require &#39;net/http&#39;<br>require &#39;cgi&#39;<br><br>cgi = CGI.new<br><br>cgi.header
(&quot;type&quot; =&gt; &quot;text/html&quot;)<br><br>begin<br>for index in (1 .. 10)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cgi.print(index.to_s + &quot;:&quot; +&nbsp;&nbsp;Time.new.to_s + &quot;&lt;br/&gt;&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sleep(1)<br>end<br>rescue StandardError =&gt; error
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;Error running script: &quot; + error<br>end<br>%&gt;

------=_Part_74598_7300691.1187129380245--