Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source
Show
Ignore:
Timestamp:
04/08/08 05:05:54 (8 months ago)
Author:
rick
Message:

Automatically parse posted JSON content for Mime::JSON requests. [rick]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/request.rb

    r9124 r9242  
    403403          when :yaml 
    404404            YAML.load(body) 
     405          when :json 
     406            if body.blank? 
     407              {} 
     408            else 
     409              data = ActiveSupport::JSON.decode(body) 
     410              data = {:_json => data} unless data.is_a?(Hash) 
     411              data.with_indifferent_access 
     412            end 
    405413          else 
    406414            {} 
     
    508516        end 
    509517 
    510  
    511518        MULTIPART_BOUNDARY = %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n 
    512519 
     
    605612          raise EOFError, "bad boundary end of body part" unless boundary_end=~/--/ 
    606613 
    607          begin 
     614          begin 
    608615            body.rewind if body.respond_to?(:rewind) 
    609          rescue Errno::ESPIPE 
     616          rescue Errno::ESPIPE 
    610617            # Handles exceptions raised by input streams that cannot be rewound 
    611618            # such as when using plain CGI under Apache 
    612          end 
     619          end 
    613620 
    614621          params