about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorBen Somers <somers.ben@gmail.com>2012-05-17 18:46:58 -0700
committerEric Wong <normalperson@yhbt.net>2012-05-18 04:17:37 +0000
commitabc6dd47ede5b96ada1ff8f37dfba73cd5fd586a (patch)
tree968e0d27a9c6c47e07f4d341b7f1b963866432f1
parent127ec6d6c733a717df79084861b0d7f36c327154 (diff)
downloadraindrops-abc6dd47ede5b96ada1ff8f37dfba73cd5fd586a.tar.gz
This enables it to behave more like a Rack
BodyProxy would, delegating methods to its body
object when it does not implement them itself.
(Also includes  a minor grammar fix to a comment.)

[ew: minor comment/whitespace fix]

Signed-off-by: Eric Wong <normalperson@yhbt.net>
-rw-r--r--lib/raindrops/middleware/proxy.rb11
-rw-r--r--test/test_middleware.rb4
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/raindrops/middleware/proxy.rb b/lib/raindrops/middleware/proxy.rb
index 53e14b5..51be3eb 100644
--- a/lib/raindrops/middleware/proxy.rb
+++ b/lib/raindrops/middleware/proxy.rb
@@ -1,7 +1,7 @@
 # -*- encoding: binary -*-
 # :stopdoc:
-# This class is by Raindrops::Middleware to proxy application response
-# bodies.  There should be no need to use it directly.
+# This class is used by Raindrops::Middleware to proxy application
+# response bodies.  There should be no need to use it directly.
 class Raindrops::Middleware::Proxy
   def initialize(body, stats)
     @body, @stats = body, stats
@@ -31,4 +31,11 @@ class Raindrops::Middleware::Proxy
     m = m.to_sym
     :close == m || @body.respond_to?(m)
   end
+
+  # Rack::BodyProxy objects use +method_missing+ to delegate methods
+  # to their bodies
+  def method_missing(*args, &block)
+    @body.send(*args, &block)
+  end
+
 end
diff --git a/test/test_middleware.rb b/test/test_middleware.rb
index eedf04a..56ce346 100644
--- a/test/test_middleware.rb
+++ b/test/test_middleware.rb
@@ -120,5 +120,9 @@ class TestMiddleware < Test::Unit::TestCase
     def orig_body.to_path; "/dev/null"; end
     assert body.respond_to?(:to_path)
     assert_equal "/dev/null", body.to_path
+
+    def orig_body.body; "this is a body"; end
+    assert body.respond_to?(:body)
+    assert_equal "this is a body", body.body
   end
 end