From 1c16649b4895012eac76f3a7f22f3382b0034a97 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 11 Mar 2006 01:23:29 +0000 Subject: Added better support for using the same actions to output for different sources depending on the Accept header [DHH] Added Base#render(:xml => xml) that works just like Base#render(:text => text), but sets the content-type to text/xml and the charset to UTF-8 [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3838 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/request.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 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 b55f63e618..16acc50011 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -54,13 +54,20 @@ module ActionController if @env['HTTP_X_POST_DATA_FORMAT'] case @env['HTTP_X_POST_DATA_FORMAT'].downcase.to_sym - when :yaml - @content_type = 'application/x-yaml' - when :xml - @content_type = 'application/xml' - end + when :yaml + @content_type = 'application/x-yaml' + when :xml + @content_type = 'application/xml' + end + end + + @content_type = Mime::Type.new(@content_type) + end + + def accepts + @accepts ||= (@env['HTTP_ACCEPT'].strip.blank? ? "*/*" : @env['HTTP_ACCEPT']).split(";").collect! do |mime_type| + Mime::Type.new(mime_type.strip) end - @content_type end # Returns true if the request's "X-Requested-With" header contains -- cgit v1.2.3