From 012d2fe51afd46fdddbf62f7ebba5102c7f3361a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 26 Feb 2011 21:02:57 +0000 Subject: middleware: split out proxy class It's easier to find this way. --- lib/raindrops/middleware.rb | 27 +-------------------------- lib/raindrops/middleware/proxy.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 26 deletions(-) create mode 100644 lib/raindrops/middleware/proxy.rb (limited to 'lib') diff --git a/lib/raindrops/middleware.rb b/lib/raindrops/middleware.rb index af3442c..1ea4863 100644 --- a/lib/raindrops/middleware.rb +++ b/lib/raindrops/middleware.rb @@ -9,6 +9,7 @@ class Raindrops::Middleware # :stopdoc: Stats = Raindrops::Struct.new(:calling, :writing) PATH_INFO = "PATH_INFO" + require "raindrops/middleware/proxy" # :startdoc: def initialize(app, opts = {}) @@ -46,32 +47,6 @@ class Raindrops::Middleware end end - class Proxy - def initialize(body, stats) - @body, @stats = body, stats - end - - # yield to the Rack server here for writing - def each - @body.each { |x| yield x } - end - - # the Rack server should call this after #each (usually ensure-d) - def close - @stats.decr_writing - @body.close if @body.respond_to?(:close) - end - - def to_path - @body.to_path - end - - def respond_to?(m) - m = m.to_sym - :close == m || @body.respond_to?(m) - end - end - def stats_response body = "calling: #{@stats.calling}\n" \ "writing: #{@stats.writing}\n" diff --git a/lib/raindrops/middleware/proxy.rb b/lib/raindrops/middleware/proxy.rb new file mode 100644 index 0000000..8b2c0c8 --- /dev/null +++ b/lib/raindrops/middleware/proxy.rb @@ -0,0 +1,26 @@ +# -*- encoding: binary -*- +class Raindrops::Middleware::Proxy + def initialize(body, stats) + @body, @stats = body, stats + end + + # yield to the Rack server here for writing + def each + @body.each { |x| yield x } + end + + # the Rack server should call this after #each (usually ensure-d) + def close + @stats.decr_writing + @body.close if @body.respond_to?(:close) + end + + def to_path + @body.to_path + end + + def respond_to?(m) + m = m.to_sym + :close == m || @body.respond_to?(m) + end +end -- cgit v1.2.3-24-ge0c7