1 # -*- encoding: binary -*-
3 module Rainbows::EventMachine::Response
4 def write_response(status, headers, body, alive)
5 if body.respond_to?(:errback) && body.respond_to?(:callback)
10 elsif body.respond_to?(:to_path)
11 st = File.stat(path = body.to_path)
14 write_headers(status, headers, alive)
15 @body = stream_file_data(path)
17 body.close if body.respond_to?(:close)
21 body.close if body.respond_to?(:close)
23 alive ? receive_data(nil) : quit
26 elsif st.socket? || st.pipe?
27 io = body_to_io(@body = body)
28 chunk = stream_response_headers(status, headers, alive)
29 m = chunk ? Rainbows::EventMachine::ResponseChunkPipe :
30 Rainbows::EventMachine::ResponsePipe
31 return EM.watch(io, m, self).notify_readable = true
33 # char or block device... WTF? fall through to body.each
35 super(status, headers, body, alive)