mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Assume that we accept what we give [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3843 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
de660957a5
commit
9e2932f816
3 changed files with 28 additions and 4 deletions
|
@ -39,6 +39,6 @@ module Mime
|
|||
JAVASCRIPT = Type.new "text/javascript"
|
||||
XML = Type.new "application/xml"
|
||||
RSS = Type.new "application/rss+xml"
|
||||
ATOM = Type.new "application/rss+atom"
|
||||
ATOM = Type.new "application/atom+xml"
|
||||
YAML = Type.new "application/x-yaml"
|
||||
end
|
|
@ -51,7 +51,7 @@ module ActionController
|
|||
return @content_type if @content_type
|
||||
|
||||
@content_type = @env['CONTENT_TYPE'].to_s.downcase
|
||||
|
||||
|
||||
if @env['HTTP_X_POST_DATA_FORMAT']
|
||||
case @env['HTTP_X_POST_DATA_FORMAT'].downcase.to_sym
|
||||
when :yaml
|
||||
|
@ -65,8 +65,14 @@ module ActionController
|
|||
end
|
||||
|
||||
def accepts
|
||||
@accepts ||= (@env['HTTP_ACCEPT'].strip.blank? ? "*/*" : @env['HTTP_ACCEPT']).split(";").collect! do |mime_type|
|
||||
Mime::Type.new(mime_type.strip)
|
||||
return @accepts if @accepts
|
||||
|
||||
@accepts = if @env['HTTP_ACCEPT'].to_s.strip.blank?
|
||||
[ content_type, Mime::ALL ]
|
||||
else
|
||||
@env['HTTP_ACCEPT'].split(";").collect! do |mime_type|
|
||||
Mime::Type.new(mime_type.strip)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -48,6 +48,14 @@ class RespondToController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def made_for_content_type
|
||||
respond_to do |type|
|
||||
type.rss { render :text => "RSS" }
|
||||
type.atom { render :text => "ATOM" }
|
||||
type.all { render :text => "Nothing" }
|
||||
end
|
||||
end
|
||||
|
||||
def rescue_action(e)
|
||||
raise unless ActionController::MissingTemplate === e
|
||||
end
|
||||
|
@ -137,4 +145,14 @@ class MimeControllerTest < Test::Unit::TestCase
|
|||
get :using_argument_defaults
|
||||
assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<person>\n <name>David</name>\n</person>\n", @response.body
|
||||
end
|
||||
|
||||
def test_with_content_type
|
||||
@request.env["CONTENT_TYPE"] = "application/atom+xml"
|
||||
get :made_for_content_type
|
||||
assert_equal "ATOM", @response.body
|
||||
|
||||
@request.env["CONTENT_TYPE"] = "application/rss+xml"
|
||||
get :made_for_content_type
|
||||
assert_equal "RSS", @response.body
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue