Commit 1d77cd6c authored by Andreas Jung's avatar Andreas Jung

- Collector #2208: rewriting/setting the 'charset' part of the content-type

        HTTP header will be done only for 'text/*'
parent 6ec027e2
......@@ -11,6 +11,9 @@ Zope Changes
- 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)
......
......@@ -343,7 +343,7 @@ class HTTPResponse(BaseResponse):
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)
......
......@@ -94,11 +94,17 @@ class HTTPResponseTests(unittest.TestCase):
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 @@ class HTTPResponseTests(unittest.TestCase):
self.assertEqual(response.body, unicode('rger',
'iso-8859-15').encode('utf-8'))
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(HTTPResponseTests, 'test'))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment