aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/middleware/body_proxy.rb
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2012-01-13 18:40:34 -0200
committerSantiago Pastorino <santiago@wyeworks.com>2012-01-13 19:46:13 -0200
commit29fdd8c7779ec2ba74cfb742e8fcef47bfae6c09 (patch)
tree6b3e2d17d08928eea7e7cf7c478610ea18f5d262 /actionpack/lib/action_dispatch/middleware/body_proxy.rb
parent161c857b9b9adce4d6fe0145120805b78d3d4c65 (diff)
downloadrails-29fdd8c7779ec2ba74cfb742e8fcef47bfae6c09.tar.gz
rails-29fdd8c7779ec2ba74cfb742e8fcef47bfae6c09.tar.bz2
rails-29fdd8c7779ec2ba74cfb742e8fcef47bfae6c09.zip
Use a BodyProxy instead of including a Module that responds to close.
Closes #4441 if Active Record is disabled assets are delivered correctly
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/body_proxy.rb')
-rw-r--r--actionpack/lib/action_dispatch/middleware/body_proxy.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/body_proxy.rb b/actionpack/lib/action_dispatch/middleware/body_proxy.rb
new file mode 100644
index 0000000000..867afe3b48
--- /dev/null
+++ b/actionpack/lib/action_dispatch/middleware/body_proxy.rb
@@ -0,0 +1,28 @@
+# Keep this file meanwhile https://github.com/rack/rack/pull/313 is not released
+module ActionDispatch
+ class BodyProxy
+ def initialize(body, &block)
+ @body, @block, @closed = body, block, false
+ end
+
+ def respond_to?(*args)
+ super or @body.respond_to?(*args)
+ end
+
+ def close
+ return if @closed
+ @closed = true
+ @body.close if @body.respond_to? :close
+ ensure
+ @block.call
+ end
+
+ def closed?
+ @closed
+ end
+
+ def method_missing(*args, &block)
+ @body.__send__(*args, &block)
+ end
+ end
+end