You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2010/07/09 01:48:18 UTC

svn commit: r962347 - /incubator/deltacloud/trunk/server/lib/sinatra/respond_to.rb

Author: lutter
Date: Thu Jul  8 23:48:17 2010
New Revision: 962347

URL: http://svn.apache.org/viewvc?rev=962347&view=rev
Log:
Fixed Chrome accept headers (rev 4)

Modified:
    incubator/deltacloud/trunk/server/lib/sinatra/respond_to.rb

Modified: incubator/deltacloud/trunk/server/lib/sinatra/respond_to.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/sinatra/respond_to.rb?rev=962347&r1=962346&r2=962347&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/sinatra/respond_to.rb (original)
+++ incubator/deltacloud/trunk/server/lib/sinatra/respond_to.rb Thu Jul  8 23:48:17 2010
@@ -48,10 +48,7 @@ module Sinatra
           rpi = request.path_info.sub(%r{\.([^\./]+)$}, '')
 
           if (not $1) or ($1 and TEXT_MIME_TYPES.include?($1.to_sym))
-
-            request.path_info=rpi
-            ext = nil
-
+            request.path_info, ext = rpi, nil
             if ! $1.nil?
               ext = $1
             elsif env['HTTP_ACCEPT'].nil? || env['HTTP_ACCEPT'].empty?
@@ -240,6 +237,13 @@ module Sinatra
       def match_accept_type(mime_types, format)
         selected = []
         accepted_types = mime_types.map {|type| Regexp.escape(type).gsub(/\\\*/,'.*') }
+        # Fix for Chrome based browsers which returns XML when 'xhtml' is requested.
+        if env['HTTP_USER_AGENT'] =~ /Chrome/ and accepted_types.size>1
+          accepted_types[0], accepted_types[1] = accepted_types[1], accepted_types[0]
+          if accepted_types[0].eql?('application/xhtml\\+xml')
+            accepted_types[0] = 'text/html'
+          end
+        end
         accepted_types.each do |at|
           format.each do |fmt, ht, handler|
             (selected = [fmt, ht, handler]) and break if ht.match(at)