Made the post_format work with content-type

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1336 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2005-05-20 18:32:04 +00:00
parent 8cc64e77cf
commit 24b13acd42
3 changed files with 15 additions and 9 deletions

View File

@ -18,14 +18,14 @@
* Added accessors to logger, params, response, session, flash, and headers from the view, so you can write <% logger.info "stuff" %> instead of <% @logger.info "others" %> -- more consistent with the preferred way of accessing these attributes and collections from the controller * Added accessors to logger, params, response, session, flash, and headers from the view, so you can write <% logger.info "stuff" %> instead of <% @logger.info "others" %> -- more consistent with the preferred way of accessing these attributes and collections from the controller
* Added support for POST data in form of YAML or XML, which is controller through the X-POST_DATA_MARSHAL header. Example request: * Added support for POST data in form of YAML or XML, which is controller through the Content-Type header. Example request:
X-POST_DATA_MARSHAL: xml Content-Type: application/xml
<request><item><content>HelloWorld</content></item></request> <request><item><content>HelloWorld</content></item></request>
...is the same as: ...is the same as:
X-POST_DATA_MARSHAL: yaml Content-Type: application/x-yaml
--- ---
item: item:
content: HelloWorld content: HelloWorld
@ -38,10 +38,10 @@
Example Curl call: Example Curl call:
curl -H 'X-POST_DATA_MARSHAL: xml' -d '<request><item><content>KillMeMore</content></item></request>' http://www.example.com/service curl -H 'Content-Type: application/xml' -d '<request><item><content>KillMeMore</content></item></request>' http://www.example.com/service
You can query to find out whether a given request came through as one of these types with: You can query to find out whether a given request came through as one of these types with:
- request.post_format? (:query_string, :xml or :yaml) - request.post_format? (:url_encoded, :xml or :yaml)
- request.formatted_post? (for either xml or yaml) - request.formatted_post? (for either xml or yaml)
- request.xml_post? - request.xml_post?
- request.yaml_post? - request.yaml_post?

View File

@ -63,8 +63,8 @@ module ActionController #:nodoc:
end end
def request_parameters def request_parameters
if env['HTTP_X_POST_DATA_FORMAT'] if formatted_post?
CGIMethods.parse_formatted_request_parameters(env['HTTP_X_POST_DATA_FORMAT'].downcase.intern, env['RAW_POST_DATA']) CGIMethods.parse_formatted_request_parameters(post_format, env['RAW_POST_DATA'])
else else
CGIMethods.parse_request_parameters(@cgi.params) CGIMethods.parse_request_parameters(@cgi.params)
end end

View File

@ -3,7 +3,6 @@ module ActionController
class AbstractRequest class AbstractRequest
# Returns both GET and POST parameters in a single hash. # Returns both GET and POST parameters in a single hash.
def parameters def parameters
# puts "#{request_parameters.inspect} | #{query_parameters.inspect} | #{path_parameters.inspect}"
@parameters ||= request_parameters.merge(query_parameters).merge(path_parameters).with_indifferent_access @parameters ||= request_parameters.merge(query_parameters).merge(path_parameters).with_indifferent_access
end end
@ -36,7 +35,14 @@ module ActionController
if env['HTTP_X_POST_DATA_FORMAT'] if env['HTTP_X_POST_DATA_FORMAT']
env['HTTP_X_POST_DATA_FORMAT'].downcase.intern env['HTTP_X_POST_DATA_FORMAT'].downcase.intern
else else
:query_string case env['HTTP_CONTENT_TYPE']
when 'application/xml', 'text/xml'
:xml
when 'application/x-yaml', 'text/x-yaml'
:yaml
else
:url_encoded
end
end end
end end