Skip to content

Commit

Permalink
Merge pull request #21252 from rodzyn/improve_params_parser
Browse files Browse the repository at this point in the history
Improve params parser
  • Loading branch information
rafaelfranca committed Aug 17, 2015
2 parents 7985908 + 9366d62 commit 15fd258
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions actionpack/lib/action_dispatch/middleware/params_parser.rb
@@ -1,9 +1,14 @@
require 'active_support/core_ext/hash/conversions'
require 'action_dispatch/http/request'
require 'active_support/core_ext/hash/indifferent_access'

module ActionDispatch
# ActionDispatch::ParamsParser works for all the requests having any Content-Length
# (like POST). It takes raw data from the request and puts it through the parser
# that is picked based on Content-Type header.
#
# In case of any error while parsing data ParamsParser::ParseError is raised.
class ParamsParser
# Raised when raw data from the request cannot be parsed by the parser
# defined for request's content mime type.
class ParseError < StandardError
attr_reader :original_exception

Expand All @@ -21,6 +26,10 @@ def initialize(message, original_exception)
}
}

# 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)
end
Expand Down

0 comments on commit 15fd258

Please sign in to comment.