aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/middleware
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-10-05 13:58:43 -0500
committerJoshua Peek <josh@joshpeek.com>2009-10-05 13:58:43 -0500
commitb480da5cd65de966ac14bbdc52b2fae3ffc06547 (patch)
tree9b62ce5b6302e289fd2a5ad4cb3fd53d6488bcc8 /actionpack/lib/action_dispatch/middleware
parent570f055c44a0b6da973f63689f8fedbef9fe32d3 (diff)
downloadrails-b480da5cd65de966ac14bbdc52b2fae3ffc06547.tar.gz
rails-b480da5cd65de966ac14bbdc52b2fae3ffc06547.tar.bz2
rails-b480da5cd65de966ac14bbdc52b2fae3ffc06547.zip
Coerce all out going body parts to Strings
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware')
-rw-r--r--actionpack/lib/action_dispatch/middleware/string_coercion.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/string_coercion.rb b/actionpack/lib/action_dispatch/middleware/string_coercion.rb
new file mode 100644
index 0000000000..232e947835
--- /dev/null
+++ b/actionpack/lib/action_dispatch/middleware/string_coercion.rb
@@ -0,0 +1,29 @@
+module ActionDispatch
+ class StringCoercion
+ class UglyBody < ActiveSupport::BasicObject
+ def initialize(body)
+ @body = body
+ end
+
+ def each
+ @body.each do |part|
+ yield part.to_s
+ end
+ end
+
+ private
+ def method_missing(*args, &block)
+ @body.__send__(*args, &block)
+ end
+ end
+
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ status, headers, body = @app.call(env)
+ [status, headers, UglyBody.new(body)]
+ end
+ end
+end