Add method_missing to Raindrops::Middleware::Proxy
[raindrops.git] / lib / raindrops / middleware / proxy.rb
blob51be3eba3cd3207bb0a722edd5b14d26a51aeeb5
1 # -*- encoding: binary -*-
2 # :stopdoc:
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
8   end
10   # yield to the Rack server here for writing
11   def each
12     @body.each { |x| yield x }
13   end
15   # the Rack server should call this after #each (usually ensure-d)
16   def close
17     @stats.decr_writing
18     @body.close if @body.respond_to?(:close)
19   end
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.
24   def to_path
25     @body.to_path
26   end
28   # Rack servers use +respond_to?+ to check for the presence of +close+
29   # and +to_path+ methods.
30   def respond_to?(m)
31     m = m.to_sym
32     :close == m || @body.respond_to?(m)
33   end
35   # Rack::BodyProxy objects use +method_missing+ to delegate methods
36   # to their bodies
37   def method_missing(*args, &block)
38     @body.send(*args, &block)
39   end
41 end