Fix IE7+MathPlayer Bug

IE7+MathPlayer do *not* like the charset parameter to be set in the
Content-Type header. Forcing Rails to omit that parameter is surprisingly
difficult.
This commit is contained in:
Jacques Distler 2008-08-20 00:22:12 -05:00
parent 37aff87d71
commit 863d60c578
2 changed files with 34 additions and 8 deletions

View file

@ -151,17 +151,20 @@ class ApplicationController < ActionController::Base
public
def set_content_type_header
response.charset = 'utf-8'
if %w(atom_with_content atom_with_headlines).include?(action_name)
response.headers['type'] = 'application/atom+xml; charset=UTF-8'
response.content_type = Mime::ATOM
elsif %w(tex).include?(action_name)
response.headers['type'] = 'text/plain; charset=UTF-8'
elsif request.env['HTTP_USER_AGENT'] =~ /Validator/ or request.env.include?('HTTP_ACCEPT') &&
response.content_type = Mime::TEXT
elsif request.user_agent =~ /Validator/ or request.env.include?('HTTP_ACCEPT') &&
Mime::Type.parse(request.env["HTTP_ACCEPT"]).include?(Mime::XHTML)
response.headers['type'] = 'application/xhtml+xml; charset=UTF-8'
elsif request.env['HTTP_USER_AGENT'] =~ /MathPlayer/
response.headers['type'] = 'application/xhtml+xml'
response.content_type = Mime::XHTML
elsif request.user_agent =~ /MathPlayer/
response.charset = nil
response.content_type = Mime::XHTML
response.extend(MathPlayerHack)
else
response.headers['type'] = 'text/html; charset=UTF-8'
response.content_type = Mime::HTML
end
end
@ -220,6 +223,12 @@ module Mime
LOOKUP["application/xhtml+xml"] = XHTML
end
module MathPlayerHack
def charset=(encoding)
self.headers["Content-Type"] = "#{content_type || Mime::HTML}"
end
end
module Instiki
module VERSION #:nodoc:
MAJOR = 0

View file

@ -19,7 +19,24 @@ class ApplicationTest < Test::Unit::TestCase
def test_utf8_header
get :show, :web => 'wiki1', :id => 'HomePage'
assert_equal 'text/html; charset=UTF-8', @response.headers['type']
assert_equal 'text/html; charset=utf-8', @response.headers['type']
end
def test_mathplayer_mime_type
@request.user_agent = 'MathPlayer'
get :show, :web => 'wiki1', :id => 'HomePage'
assert_equal 'application/xhtml+xml', @response.headers['type']
end
def test_validator_mime_type
@request.user_agent = 'Validator'
get :show, :web => 'wiki1', :id => 'HomePage'
assert_equal 'application/xhtml+xml; charset=utf-8', @response.headers['type']
end
def test_tex_mime_type
get :tex, :web => 'wiki1', :id => 'HomePage'
assert_equal 'text/plain; charset=utf-8', @response.headers['type']
end
def test_connect_to_model_unknown_wiki