Commits

Sylvain Hellegouarch committed 9b1cb75

no much point in computing the charset when it's not expected anyway

Comments (0)

Files changed (1)

cherrypy/lib/encoding.py

             body.append(chunk)
         self.body = body
         return True
-    
+
     def find_acceptable_charset(self):
         request = cherrypy.serving.request
         response = cherrypy.serving.response
         ct = response.headers.elements("Content-Type")
         if self.debug:
             cherrypy.log('Content-Type: %r' % [str(h) for h in ct], 'TOOLS.ENCODE')
-        if ct:
+        if ct and self.add_charset:
             ct = ct[0]
             if self.text_only:
                 if ct.value.lower().startswith("text/"):
             if do_find:
                 # Set "charset=..." param on response Content-Type header
                 ct.params['charset'] = self.find_acceptable_charset()
-                if self.add_charset:
-                    if self.debug:
-                        cherrypy.log('Setting Content-Type %s' % ct,
-                                     'TOOLS.ENCODE')
-                    response.headers["Content-Type"] = str(ct)
+                if self.debug:
+                    cherrypy.log('Setting Content-Type %s' % ct,
+                                 'TOOLS.ENCODE')
+                response.headers["Content-Type"] = str(ct)
 
         return self.body