From 4d594cffcfc93b37fad4e423ec8593299e50133c Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Tue, 8 Apr 2008 05:05:54 +0000 Subject: Automatically parse posted JSON content for Mime::JSON requests. [rick] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9242 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/request.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_controller/request.rb') diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index 745161def8..823271d13f 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -402,6 +402,14 @@ EOM body.blank? ? {} : Hash.from_xml(body).with_indifferent_access when :yaml YAML.load(body) + when :json + if body.blank? + {} + else + data = ActiveSupport::JSON.decode(body) + data = {:_json => data} unless data.is_a?(Hash) + data.with_indifferent_access + end else {} end @@ -507,7 +515,6 @@ EOM end end - MULTIPART_BOUNDARY = %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n EOL = "\015\012" @@ -604,12 +611,12 @@ EOM end raise EOFError, "bad boundary end of body part" unless boundary_end=~/--/ - begin + begin body.rewind if body.respond_to?(:rewind) - rescue Errno::ESPIPE + rescue Errno::ESPIPE # Handles exceptions raised by input streams that cannot be rewound # such as when using plain CGI under Apache - end + end params end -- cgit v1.2.3