Default mime type for XML should be application/xml [DHH]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3849 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2006-03-12 18:50:14 +00:00
parent e3ea34f7d3
commit 09cec78248
2 changed files with 28 additions and 13 deletions

@ -30,27 +30,30 @@ def ==(mime_type)
end end
end end
ALL = Type.new "*/*", :all ALL = Type.new "*/*", :all
HTML = Type.new "text/html", :html HTML = Type.new "text/html", :html, %w( application/xhtml+xml )
JS = Type.new "text/javascript", :js, %w( application/javascript application/x-javascript ) JS = Type.new "text/javascript", :js, %w( application/javascript application/x-javascript )
XML = Type.new "text/xml", :xml, %w( application/xml application/x-xml ) XML = Type.new "application/xml", :xml, %w( text/xml application/x-xml )
RSS = Type.new "application/rss+xml", :rss RSS = Type.new "application/rss+xml", :rss
ATOM = Type.new "application/atom+xml", :atom ATOM = Type.new "application/atom+xml", :atom
YAML = Type.new "application/x-yaml", :yaml YAML = Type.new "application/x-yaml", :yaml
LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) } LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) }
LOOKUP["*/*"] = ALL LOOKUP["*/*"] = ALL
LOOKUP["text/html"] = HTML LOOKUP["text/html"] = HTML
LOOKUP["application/rss+xml"] = RSS LOOKUP["application/xhtml+xml"] = HTML
LOOKUP["application/atom+xml"] = ATOM
LOOKUP["application/x-yaml"] = YAML LOOKUP["application/xml"] = XML
LOOKUP["text/xml"] = XML
LOOKUP["application/x-xml"] = XML
LOOKUP["text/javascript"] = JS LOOKUP["text/javascript"] = JS
LOOKUP["application/javascript"] = JS LOOKUP["application/javascript"] = JS
LOOKUP["application/x-javascript"] = JS LOOKUP["application/x-javascript"] = JS
LOOKUP["text/xml"] = XML LOOKUP["application/rss+xml"] = RSS
LOOKUP["application/xml"] = XML LOOKUP["application/atom+xml"] = ATOM
LOOKUP["application/x-xml"] = XML LOOKUP["application/x-yaml"] = YAML
end end

@ -183,4 +183,16 @@ def test_custom_types
get :custom_type_handling get :custom_type_handling
assert_equal 'HTML', @response.body assert_equal 'HTML', @response.body
end end
def test_xhtml_alias
@request.env["HTTP_ACCEPT"] = "application/xhtml+xml,application/xml"
get :html_or_xml
assert_equal 'HTML', @response.body
end
def test_firefox_simulation
@request.env["HTTP_ACCEPT"] = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
get :html_or_xml
assert_equal 'HTML', @response.body
end
end end