From b480da5cd65de966ac14bbdc52b2fae3ffc06547 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 5 Oct 2009 13:58:43 -0500 Subject: Coerce all out going body parts to Strings --- .../action_dispatch/middleware/string_coercion.rb | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 actionpack/lib/action_dispatch/middleware/string_coercion.rb (limited to 'actionpack/lib/action_dispatch/middleware') 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 -- cgit v1.2.3