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

Andreas Jung andreas at andreas-jung.com
Sun Oct 8 04:30:20 EDT 2006


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

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

-=-
Modified: Zope/branches/2.10/doc/CHANGES.txt
===================================================================
--- Zope/branches/2.10/doc/CHANGES.txt	2006-10-08 06:16:21 UTC (rev 70563)
+++ Zope/branches/2.10/doc/CHANGES.txt	2006-10-08 08:30:16 UTC (rev 70564)
@@ -4,6 +4,14 @@
   Change information for previous versions of Zope can be found in the
   file HISTORY.txt.
 
+  Zope 2.10.0 (unreleased)
+
+    Bugs fixed
+
+      - Collector #2208: rewriting/setting the 'charset' part of the content-type
+        HTTP header will be done only for 'text/*'
+
+
   Zope 2.10.0 (2006/10/04)
 
     Bugs fixed

Modified: Zope/branches/2.10/lib/python/ZPublisher/HTTPResponse.py
===================================================================
--- Zope/branches/2.10/lib/python/ZPublisher/HTTPResponse.py	2006-10-08 06:16:21 UTC (rev 70563)
+++ Zope/branches/2.10/lib/python/ZPublisher/HTTPResponse.py	2006-10-08 08:30:16 UTC (rev 70564)
@@ -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.10/lib/python/ZPublisher/tests/testHTTPResponse.py
===================================================================
--- Zope/branches/2.10/lib/python/ZPublisher/tests/testHTTPResponse.py	2006-10-08 06:16:21 UTC (rev 70563)
+++ Zope/branches/2.10/lib/python/ZPublisher/tests/testHTTPResponse.py	2006-10-08 08:30:16 UTC (rev 70564)
@@ -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'),
@@ -117,9 +123,9 @@
 
     def test_XMLEncodingRecoding(self):
         xml = u'<?xml version="1.0" encoding="iso-8859-15" ?>\n<foo><bar/></foo>'
-        response = self._makeOne(body=xml, headers={'content-type': 'application/foo; charset=utf-8'})
+        response = self._makeOne(body=xml, headers={'content-type': 'text/xml; charset=utf-8'})
         self.assertEqual(xml.replace('iso-8859-15', 'utf-8')==response.body, True)
-        response = self._makeOne(body=xml, headers={'content-type': 'application/foo; charset=iso-8859-15'})
+        response = self._makeOne(body=xml, headers={'content-type': 'text/xml; charset=iso-8859-15'})
         self.assertEqual(xml==response.body, True)
 
 



More information about the Zope-Checkins mailing list