diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-01-05 17:39:11 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-01-06 14:14:30 -0800 |
commit | 2cb26ba8084cd37996330616b885de1c780d848e (patch) | |
tree | 6e829d0c1d4c49e666e97dacdfcc16e8eea0482d /lib/rainbows/event_machine/response.rb | |
parent | 31a93152c8977f31045bd182ae99df4ebd088abf (diff) | |
download | rainbows-2cb26ba8084cd37996330616b885de1c780d848e.tar.gz |
This will allow Coolio to use it, too.
Diffstat (limited to 'lib/rainbows/event_machine/response.rb')
-rw-r--r-- | lib/rainbows/event_machine/response.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/rainbows/event_machine/response.rb b/lib/rainbows/event_machine/response.rb new file mode 100644 index 0000000..49bcbd5 --- /dev/null +++ b/lib/rainbows/event_machine/response.rb @@ -0,0 +1,38 @@ +# -*- encoding: binary -*- +# :enddoc: +module Rainbows::EventMachine::Response + def write_response(status, headers, body, alive) + if body.respond_to?(:errback) && body.respond_to?(:callback) + @body = body + body.callback { quit } + body.errback { quit } + alive = true + elsif body.respond_to?(:to_path) + st = File.stat(path = body.to_path) + + if st.file? + write_headers(status, headers, alive) + @body = stream_file_data(path) + @body.errback do + body.close if body.respond_to?(:close) + quit + end + @body.callback do + body.close if body.respond_to?(:close) + @body = nil + alive ? receive_data(nil) : quit + end + return + elsif st.socket? || st.pipe? + io = body_to_io(@body = body) + chunk = stream_response_headers(status, headers, alive) + m = chunk ? Rainbows::EventMachine::ResponseChunkPipe : + Rainbows::EventMachine::ResponsePipe + return EM.watch(io, m, self).notify_readable = true + end + # char or block device... WTF? fall through to body.each + end + super(status, headers, body, alive) + quit unless alive + end +end |