[Zope-Checkins] SVN: Zope/trunk/ - Collector #2208:
rewriting/setting the 'charset' part of the content-type
Andreas Jung
andreas at andreas-jung.com
Sat Oct 7 08:09:21 EDT 2006
Log message for revision 70560:
- Collector #2208: rewriting/setting the 'charset' part of the content-type
HTTP header will be done only for 'text/*'
Changed:
U Zope/trunk/doc/CHANGES.txt
U Zope/trunk/lib/python/ZPublisher/HTTPResponse.py
U Zope/trunk/lib/python/ZPublisher/tests/testHTTPResponse.py
-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt 2006-10-07 11:18:42 UTC (rev 70559)
+++ Zope/trunk/doc/CHANGES.txt 2006-10-07 12:09:20 UTC (rev 70560)
@@ -34,6 +34,9 @@
Bugs Fixed
+ - Collector #2208: rewriting/setting the 'charset' part of the content-type
+ HTTP header will be done only for 'text/*'
+
- Call setDefaultSkin on new requests created as the result of
ConflictError retries.
Modified: Zope/trunk/lib/python/ZPublisher/HTTPResponse.py
===================================================================
--- Zope/trunk/lib/python/ZPublisher/HTTPResponse.py 2006-10-07 11:18:42 UTC (rev 70559)
+++ Zope/trunk/lib/python/ZPublisher/HTTPResponse.py 2006-10-07 12:09:20 UTC (rev 70560)
@@ -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/trunk/lib/python/ZPublisher/tests/testHTTPResponse.py
===================================================================
--- Zope/trunk/lib/python/ZPublisher/tests/testHTTPResponse.py 2006-10-07 11:18:42 UTC (rev 70559)
+++ Zope/trunk/lib/python/ZPublisher/tests/testHTTPResponse.py 2006-10-07 12:09:20 UTC (rev 70560)
@@ -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