class ActionDispatch::ParamsParser
Constants
- DEFAULT_PARSERS
Public Class Methods
new(app, parsers = {})
click to toggle source
# File lib/action_dispatch/middleware/params_parser.rb, line 18 def initialize(app, parsers = {}) @app, @parsers = app, DEFAULT_PARSERS.merge(parsers) end
Public Instance Methods
call(env)
click to toggle source
# File lib/action_dispatch/middleware/params_parser.rb, line 22 def call(env) if params = parse_formatted_parameters(env) env["action_dispatch.request.request_parameters"] = params end @app.call(env) end
Private Instance Methods
logger(env)
click to toggle source
# File lib/action_dispatch/middleware/params_parser.rb, line 56 def logger(env) env['action_dispatch.logger'] || ActiveSupport::Logger.new($stderr) end
parse_formatted_parameters(env)
click to toggle source
# File lib/action_dispatch/middleware/params_parser.rb, line 31 def parse_formatted_parameters(env) request = Request.new(env) return false if request.content_length.zero? strategy = @parsers[request.content_mime_type] return false unless strategy case strategy when Proc strategy.call(request.raw_post) when :json data = ActiveSupport::JSON.decode(request.raw_post) data = {:_json => data} unless data.is_a?(Hash) Request::Utils.deep_munge(data).with_indifferent_access else false end rescue => e # JSON or Ruby code block errors logger(env).debug "Error occurred while parsing request parameters.\nContents:\n\n#{request.raw_post}" raise ParseError.new(e.message, e) end