Method: Merb::ControllerMixin#render_chunked
- Defined in:
- lib/merb-core/controller/mixins/controller.rb
#render_chunked(&blk) ⇒ Object
Renders the block given as a parameter using chunked encoding.
Parameters
- &blk
-
A block that, when called, will use send_chunks to send chunks of data down to the server. The chunking will terminate once the block returns.
Examples
def stream
prefix = '<p>'
suffix = "</p>\r\n"
render_chunked do
IO.popen("cat /tmp/test.log") do |io|
done = false
until done
sleep 0.3
line = io.gets.chomp
if line == 'EOF'
done = true
else
send_chunk(prefix + line + suffix)
end
end
end
end
end
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/merb-core/controller/mixins/controller.rb', line 47 def render_chunked(&blk) must_support_streaming! headers['Transfer-Encoding'] = 'chunked' Proc.new { |response| @response = response response.send_status_no_connection_close('') response.send_header blk.call response.write("0\r\n\r\n") } end |