Permalink
Browse files

Merge branch '2-3-stable' of github.com:rails/rails into 2-3-stable

  • Loading branch information...
2 parents d796fc6 + 0f0f977 commit 27b935dec65b2346fcdfc4608d0ed022135385e9 @dhh dhh committed Nov 23, 2009
Showing with 3 additions and 49 deletions.
  1. +3 −12 actionpack/lib/action_controller/request.rb
  2. +0 −37 actionpack/test/controller/request_test.rb
@@ -99,25 +99,15 @@ def media_type
content_type.to_s
end
- # Regular expression to match the Internet Explorer user agent string.
- INTERNET_EXPLORER = /MSIE\s[\d\.]+;/
-
- # Returns true if the user agent is Internet Explorer.
- def internet_explorer?
- user_agent =~ INTERNET_EXPLORER
- end
-
- # Returns the accepted MIME types for the request.
+ # Returns the accepted MIME type for the request.
def accepts
@accepts ||= begin
header = @env['HTTP_ACCEPT'].to_s.strip
if header.empty?
[content_type, Mime::ALL].compact
else
- accepts = Mime::Type.parse(header)
- accepts.unshift(Mime::HTML, Mime::XML) if internet_explorer?
- accepts
+ Mime::Type.parse(header)
end
end
end
@@ -174,6 +164,7 @@ def format
end
end
+
# Sets the \format by string extension, which can be used to force custom formats
# that are not controlled by the extension.
#
@@ -371,43 +371,6 @@ def test_content_type_with_charset
assert_equal Mime::XML, request.content_type
end
- def test_internet_explorer_user_agent_check
- assert([
- "curl 7.16.1 (i386-portbld-freebsd6.2) libcurl/7.16.1 OpenSSL/0.9.7m zlib/1.2.3",
- "Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.2.15 Version/10.00",
- "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_1; en-us) AppleWebKit/531.9 (KHTML, like Gecko) Version/4.0.3 Safari/531.9",
- "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en; rv:1.8.1.23) Gecko/20090815 Camino/1.6.9 (like Firefox/2.0.0.23)",
- "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5"
- ].all? do |user_agent|
- !stub_request('HTTP_USER_AGENT' => user_agent).internet_explorer?
- end)
-
- assert([
- "Mozilla/4.0 (Windows; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)",
- "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; )",
- "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Win64; x64; Trident/4.0)"
- ].all? do |user_agent|
- stub_request('HTTP_USER_AGENT' => user_agent).internet_explorer?
- end)
- end
-
- def test_accepts_without_user_agent
- request = stub_request 'HTTP_ACCEPT' => 'text/html, text/csv, */*'
- assert_equal [Mime::HTML, Mime::CSV, Mime::ALL], request.accepts
- end
-
- def test_accepts_for_regular_user_agent
- request = stub_request 'HTTP_USER_AGENT' => "curl 7.16.1 (i386-portbld-freebsd6.2) libcurl/7.16.1 OpenSSL/0.9.7m zlib/1.2.3", 'HTTP_ACCEPT' => 'text/html, text/csv, */*'
- assert_equal [Mime::HTML, Mime::CSV, Mime::ALL], request.accepts
- end
-
- def test_accepts_for_internet_explorer
- request = stub_request 'HTTP_USER_AGENT' => 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Win64; x64)',
- 'HTTP_ACCEPT' => "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/x-shockwave-flash, application/x-silverlight, */*"
- assert_equal 16, request.accepts.length
- assert_equal [Mime::HTML, Mime::XML], request.accepts[0..1]
- end
-
def test_user_agent
request = stub_request 'HTTP_USER_AGENT' => 'TestAgent'
assert_equal 'TestAgent', request.user_agent

0 comments on commit 27b935d

Please sign in to comment.