rev/deferred_response: cleanups
[rainbows.git] / lib / rainbows / rev / deferred_response.rb
blobf0172d65bee0316f83a46f44f58c369c648996ae
1 # -*- encoding: binary -*-
2 # :enddoc:
4 # this is class is specific to Rev for writing large static files
5 # or proxying IO-derived objects
6 class Rainbows::Rev::DeferredResponse < ::Rev::IO
7   def initialize(io, client, do_chunk, body)
8     super(io)
9     @client, @do_chunk, @body = client, do_chunk, body
10   end
12   def on_read(data)
13     @do_chunk and @client.write("#{data.size.to_s(16)}\r\n")
14     @client.write(data)
15     @do_chunk and @client.write("\r\n")
16   end
18   def on_close
19     @do_chunk and @client.write("0\r\n\r\n")
20     @client.next
21     @body.respond_to?(:close) and @body.close
22   end
23 end