mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Added support for POST data in form of YAML or XML, which is controller through the POST_DATA_MARSHAL header
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1303 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -25,7 +25,7 @@ class CGI #:nodoc:
|
||||
end
|
||||
|
||||
def request_parameters
|
||||
CGIMethods.parse_request_parameters(params)
|
||||
CGIMethods.parse_request_parameters(params, env_table)
|
||||
end
|
||||
|
||||
def redirect(where)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
require 'cgi'
|
||||
require 'action_controller/vendor/xml_simple'
|
||||
|
||||
# Static methods for parsing the query and request parameters that can be used in
|
||||
# a CGI extension class or testing in isolation.
|
||||
@@ -16,13 +17,13 @@ class CGIMethods #:nodoc:
|
||||
v = CGI.unescape(v) unless v.nil?
|
||||
|
||||
if k =~ /(.*)\[\]$/
|
||||
if parsed_params.has_key? $1
|
||||
parsed_params[$1] << v
|
||||
else
|
||||
parsed_params[$1] = [v]
|
||||
end
|
||||
if parsed_params.has_key? $1
|
||||
parsed_params[$1] << v
|
||||
else
|
||||
parsed_params[$1] = [v]
|
||||
end
|
||||
else
|
||||
parsed_params[k] = v.nil? ? nil : v
|
||||
parsed_params[k] = v.nil? ? nil : v
|
||||
end
|
||||
}
|
||||
|
||||
@@ -47,6 +48,18 @@ class CGIMethods #:nodoc:
|
||||
return parsed_params
|
||||
end
|
||||
|
||||
def self.parse_formatted_request_parameters(format, raw_post_data)
|
||||
case format
|
||||
when :xml
|
||||
return XmlSimple.xml_in(raw_post_data, 'ForceArray' => false)
|
||||
when :yaml
|
||||
return YAML.load(raw_post_data)
|
||||
end
|
||||
rescue Object => e
|
||||
{ "exception" => "#{e.message} (#{e.class})", "backtrace" => e.backtrace,
|
||||
"raw_post_data" => raw_post_data, "format" => format }
|
||||
end
|
||||
|
||||
private
|
||||
def CGIMethods.get_typed_value(value)
|
||||
if value.respond_to?(:content_type) && !value.content_type.empty?
|
||||
|
||||
@@ -63,7 +63,11 @@ module ActionController #:nodoc:
|
||||
end
|
||||
|
||||
def request_parameters
|
||||
CGIMethods.parse_request_parameters(@cgi.params)
|
||||
if env['HTTP_POST_DATA_FORMAT']
|
||||
CGIMethods.parse_formatted_request_parameters(env['HTTP_POST_DATA_FORMAT'].downcase.intern, env['RAW_POST_DATA'])
|
||||
else
|
||||
CGIMethods.parse_request_parameters(@cgi.params)
|
||||
end
|
||||
end
|
||||
|
||||
def env
|
||||
|
||||
@@ -30,6 +30,27 @@ module ActionController
|
||||
def head?
|
||||
method == :head
|
||||
end
|
||||
|
||||
|
||||
def post_format
|
||||
if env['POST_DATA_FORMAT']
|
||||
env['POST_DATA_FORMAT'].downcase.intern
|
||||
else
|
||||
:query_string
|
||||
end
|
||||
end
|
||||
|
||||
def formatted_post?
|
||||
[ :xml, :yaml ].include?(post_format) && post?
|
||||
end
|
||||
|
||||
def xml_post?
|
||||
post_format == :xml && post?
|
||||
end
|
||||
|
||||
def yaml_post?
|
||||
post_format == :yaml && post?
|
||||
end
|
||||
|
||||
|
||||
# Determine originating IP address. REMOTE_ADDR is the standard
|
||||
|
||||
1019
actionpack/lib/action_controller/vendor/xml_simple.rb
vendored
Normal file
1019
actionpack/lib/action_controller/vendor/xml_simple.rb
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user