diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-09-18 11:46:51 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-09-18 11:46:51 -0700 |
commit | b93c226d19615fe504f9e12d6c0ee2d70683e5fa (patch) | |
tree | cd3cdb9234445e13a7fecaec2f4014f2c4122dbc /actionpack/lib/action_dispatch/middleware | |
parent | 91d05082e43008f2617d468fdd6c0de95855fe7f (diff) | |
download | rails-b93c226d19615fe504f9e12d6c0ee2d70683e5fa.tar.gz rails-b93c226d19615fe504f9e12d6c0ee2d70683e5fa.tar.bz2 rails-b93c226d19615fe504f9e12d6c0ee2d70683e5fa.zip |
push the parameter parsers on to the class
The middleware stack is a singleton in the application (one instance is
shared for the entire application) which means that there was only one
opportunity to set the parameter parsers. Since there is only one set
of parameter parsers in an app, lets just configure them on the request
class (since that is where they are used).
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/params_parser.rb | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/params_parser.rb b/actionpack/lib/action_dispatch/middleware/params_parser.rb index 00c3324b06..ef55401015 100644 --- a/actionpack/lib/action_dispatch/middleware/params_parser.rb +++ b/actionpack/lib/action_dispatch/middleware/params_parser.rb @@ -18,26 +18,16 @@ module ActionDispatch end end - DEFAULT_PARSERS = { - Mime::JSON => lambda { |raw_post| - data = ActiveSupport::JSON.decode(raw_post) - data.is_a?(Hash) ? data : {:_json => data} - } - } - # Create a new +ParamsParser+ middleware instance. # # The +parsers+ argument can take Hash of parsers where key is identifying # content mime type, and value is a lambda that is going to process data. def initialize(app, parsers = {}) - @app, @parsers = app, DEFAULT_PARSERS.merge(parsers) + @app = app + ActionDispatch::Request.parameter_parsers = ActionDispatch::Request::DEFAULT_PARSERS.merge(parsers) end def call(env) - request = Request.new(env) - - request.params_parsers = @parsers - @app.call(env) end end |