1 # -*- encoding: binary -*-
2 # frozen_string_literal: false
4 # This class is used by Raindrops::Middleware to proxy application
5 # response bodies. There should be no need to use it directly.
6 class Raindrops::Middleware::Proxy
7 def initialize(body, stats)
8 @body, @stats = body, stats
11 # yield to the Rack server here for writing
13 @body.each { |x| yield x }
16 # the Rack server should call this after #each (usually ensure-d)
19 @body.close if @body.respond_to?(:close)
22 # Some Rack servers can optimize response processing if it responds
23 # to +to_path+ via the sendfile(2) system call, we proxy +to_path+
24 # to the underlying body if possible.
29 # Rack servers use +respond_to?+ to check for the presence of +close+
30 # and +to_path+ methods.
31 def respond_to?(m, include_all = false)
33 :close == m || @body.respond_to?(m, include_all)
36 # Avoid breaking users of non-standard extensions (e.g. #body)
37 # Rack::BodyProxy does the same.
38 def method_missing(*args, &block)
39 @body.__send__(*args, &block)