[Zope-Checkins] SVN: Zope/branches/2.9/ - Collector #2208: rewriting/setting the 'charset' part of the content-type

Andreas Jung andreas at andreas-jung.com
Sun Oct 8 04:41:16 EDT 2006


Log message for revision 70565:
        - Collector #2208: rewriting/setting the 'charset' part of the content-type
          HTTP header will be done only for 'text/*'
  
  

Changed:
  U   Zope/branches/2.9/doc/CHANGES.txt
  U   Zope/branches/2.9/lib/python/ZPublisher/HTTPResponse.py
  U   Zope/branches/2.9/lib/python/ZPublisher/tests/testHTTPResponse.py

-=-
Modified: Zope/branches/2.9/doc/CHANGES.txt
===================================================================
--- Zope/branches/2.9/doc/CHANGES.txt	2006-10-08 08:30:16 UTC (rev 70564)
+++ Zope/branches/2.9/doc/CHANGES.txt	2006-10-08 08:41:15 UTC (rev 70565)
@@ -11,7 +11,10 @@
     
       - Collector #2205: fixed wrong logger argument in ZRDB/Connection.py
 
+      - Collector #2208: rewriting/setting the 'charset' part of the content-type
+        HTTP header will be done only for 'text/*'
 
+
   Zope 2.9.5 (2006/10/03)
 
    Bugs fixed

Modified: Zope/branches/2.9/lib/python/ZPublisher/HTTPResponse.py
===================================================================
--- Zope/branches/2.9/lib/python/ZPublisher/HTTPResponse.py	2006-10-08 08:30:16 UTC (rev 70564)
+++ Zope/branches/2.9/lib/python/ZPublisher/HTTPResponse.py	2006-10-08 08:41:15 UTC (rev 70565)
@@ -343,7 +343,7 @@
             self.setHeader('content-type', c)
         else:
             c = self.headers['content-type']
-            if not 'charset=' in  c:
+            if c.startswith('text/') and not 'charset=' in  c:
                 c = '%s; charset=%s' % (c, default_encoding)                
                 self.setHeader('content-type', c)
 

Modified: Zope/branches/2.9/lib/python/ZPublisher/tests/testHTTPResponse.py
===================================================================
--- Zope/branches/2.9/lib/python/ZPublisher/tests/testHTTPResponse.py	2006-10-08 08:30:16 UTC (rev 70564)
+++ Zope/branches/2.9/lib/python/ZPublisher/tests/testHTTPResponse.py	2006-10-08 08:41:15 UTC (rev 70565)
@@ -94,11 +94,17 @@
         self.assertEqual(response.headers.get('content-type'),
                          'text/plain; charset=iso-8859-15')
 
-    def test_charset_application_header(self):
+    def test_charset_application_header_no_header(self):
         response = self._makeOne(body='foo',
                     headers={'content-type': 'application/foo'})
         self.assertEqual(response.headers.get('content-type'),
-                         'application/foo; charset=iso-8859-15')
+                         'application/foo')
+
+    def test_charset_application_header_with_header(self):
+        response = self._makeOne(body='foo',
+                    headers={'content-type': 'application/foo; charset: something'})
+        self.assertEqual(response.headers.get('content-type'),
+                         'application/foo; charset: something')
     
     def test_charset_application_header_unicode(self):
         response = self._makeOne(body=unicode('ärger', 'iso-8859-15'),
@@ -115,6 +121,7 @@
         self.assertEqual(response.body, unicode('ärger',
                          'iso-8859-15').encode('utf-8'))
 
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(HTTPResponseTests, 'test'))



More information about the Zope-Checkins mailing list