Parent

Class Index [+]

Quicksearch

ActionDispatch::ParamsParser

Constants

DEFAULT_PARSERS

Public Class Methods

new(app, parsers = {}) click to toggle source
    # File lib/action_dispatch/middleware/params_parser.rb, line 12
12:     def initialize(app, parsers = {})
13:       @app, @parsers = app, DEFAULT_PARSERS.merge(parsers)
14:     end

Public Instance Methods

call(env) click to toggle source
    # File lib/action_dispatch/middleware/params_parser.rb, line 16
16:     def call(env)
17:       if params = parse_formatted_parameters(env)
18:         env["action_dispatch.request.request_parameters"] = params
19:       end
20: 
21:       @app.call(env)
22:     end

Private Instance Methods

content_type_from_legacy_post_data_format_header(env) click to toggle source
    # File lib/action_dispatch/middleware/params_parser.rb, line 65
65:       def content_type_from_legacy_post_data_format_header(env)
66:         if x_post_format = env['HTTP_X_POST_DATA_FORMAT']
67:           case x_post_format.to_s.downcase
68:           when 'yaml' then return Mime::YAML
69:           when 'xml'  then return Mime::XML
70:           end
71:         end
72: 
73:         nil
74:       end
logger() click to toggle source
    # File lib/action_dispatch/middleware/params_parser.rb, line 76
76:       def logger
77:         defined?(Rails.logger) ? Rails.logger : Logger.new($stderr)
78:       end
parse_formatted_parameters(env) click to toggle source
    # File lib/action_dispatch/middleware/params_parser.rb, line 25
25:       def parse_formatted_parameters(env)
26:         request = Request.new(env)
27: 
28:         return false if request.content_length.zero?
29: 
30:         mime_type = content_type_from_legacy_post_data_format_header(env) ||
31:           request.content_mime_type
32: 
33:         strategy = @parsers[mime_type]
34: 
35:         return false unless strategy
36: 
37:         case strategy
38:         when Proc
39:           strategy.call(request.raw_post)
40:         when :xml_simple, :xml_node
41:           data = Hash.from_xml(request.body.read) || {}
42:           request.body.rewind if request.body.respond_to?(:rewind)
43:           data.with_indifferent_access
44:         when :yaml
45:           YAML.load(request.raw_post)
46:         when :json
47:           data = ActiveSupport::JSON.decode(request.body)
48:           request.body.rewind if request.body.respond_to?(:rewind)
49:           data = {:_json => data} unless data.is_a?(Hash)
50:           data.with_indifferent_access
51:         else
52:           false
53:         end
54:       rescue Exception => e # YAML, XML or Ruby code block errors
55:         logger.debug "Error occurred while parsing request parameters.\nContents:\n\n#{request.raw_post}"
56: 
57:         raise
58:           { "body"           => request.raw_post,
59:             "content_type"   => request.content_mime_type,
60:             "content_length" => request.content_length,
61:             "exception"      => "#{e.message} (#{e.class})",
62:             "backtrace"      => e.backtrace }
63:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.