1 # -*- encoding: binary -*-
3 # This class is used by Raindrops::Middleware to proxy application
4 # response bodies. There should be no need to use it directly.
5 class Raindrops::Middleware::Proxy
6 def initialize(body, stats)
7 @body, @stats = body, stats
10 # yield to the Rack server here for writing
12 @body.each { |x| yield x }
15 # the Rack server should call this after #each (usually ensure-d)
18 @body.close if @body.respond_to?(:close)
21 # Some Rack servers can optimize response processing if it responds
22 # to +to_path+ via the sendfile(2) system call, we proxy +to_path+
23 # to the underlying body if possible.
28 # Rack servers use +respond_to?+ to check for the presence of +close+
29 # and +to_path+ methods.
32 :close == m || @body.respond_to?(m)
35 # Rack::BodyProxy objects use +method_missing+ to delegate methods
37 def method_missing(*args, &block)
38 @body.send(*args, &block)