diff options
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/params_parser.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/params_parser.rb | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/params_parser.rb b/actionpack/lib/action_dispatch/middleware/params_parser.rb index e83cf9236b..32ccb5c931 100644 --- a/actionpack/lib/action_dispatch/middleware/params_parser.rb +++ b/actionpack/lib/action_dispatch/middleware/params_parser.rb @@ -2,11 +2,13 @@ require 'active_support/json' module ActionDispatch class ParamsParser - ActionController::Base.param_parsers[Mime::XML] = :xml_simple - ActionController::Base.param_parsers[Mime::JSON] = :json + DEFAULT_PARSERS = { + Mime::XML => :xml_simple, + Mime::JSON => :json + } - def initialize(app) - @app = app + def initialize(app, parsers = {}) + @app, @parsers = app, DEFAULT_PARSERS.merge(parsers) end def call(env) @@ -24,7 +26,7 @@ module ActionDispatch return false if request.content_length.zero? mime_type = content_type_from_legacy_post_data_format_header(env) || request.content_type - strategy = ActionController::Base.param_parsers[mime_type] + strategy = @parsers[mime_type] return false unless strategy @@ -47,6 +49,8 @@ module ActionDispatch false end rescue Exception => e # YAML, XML or Ruby code block errors + logger.debug "Error occurred while parsing request parameters.\nContents:\n\n#{request.raw_post}" + raise { "body" => request.raw_post, "content_type" => request.content_type, @@ -67,5 +71,9 @@ module ActionDispatch nil end + + def logger + defined?(Rails.logger) ? Rails.logger : Logger.new($stderr) + end end end |