1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| | # -*- encoding: binary -*-
# :enddoc:
module Rainbows
module Rev
# this is class is specific to Rev for writing large static files
# or proxying IO-derived objects
class DeferredResponse < ::Rev::IO
include Rainbows::Const
def initialize(io, client, do_chunk, body)
super(io)
@client, @do_chunk, @body = client, do_chunk, body
end
def on_read(data)
@do_chunk and @client.write(sprintf("%x\r\n", data.size))
@client.write(data)
@do_chunk and @client.write("\r\n")
end
def on_close
@do_chunk and @client.write("0\r\n\r\n")
@client.quit
@body.respond_to?(:close) and @body.close
end
end # class DeferredResponse
end # module Rev
end # module Rainbows
|