Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Coerce all out going body parts to Strings

  • Loading branch information...
commit 11cce5bde9872da95b83ce627f95c2444d1442df 1 parent 1d7412b
@josh josh authored
View
1  actionpack/lib/action_controller.rb
@@ -70,6 +70,7 @@ def self.load_all!
autoload :SessionManagement, 'action_controller/session_management'
autoload :StatusCodes, 'action_controller/status_codes'
autoload :Streaming, 'action_controller/streaming'
+ autoload :StringCoercion, 'action_controller/string_coercion'
autoload :TestCase, 'action_controller/test_case'
autoload :TestProcess, 'action_controller/test_process'
autoload :Translation, 'action_controller/translation'
View
2  actionpack/lib/action_controller/middlewares.rb
@@ -10,3 +10,5 @@
use "ActionController::ParamsParser"
use "Rack::MethodOverride"
use "Rack::Head"
+
+use "ActionController::StringCoercion"
View
29 actionpack/lib/action_controller/string_coercion.rb
@@ -0,0 +1,29 @@
+module ActionController
+ 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

1 comment on commit 11cce5b

@gtd

Commit message sounds vaguely sinister.

Please sign in to comment.
Something went wrong with that request. Please try again.