Commit 020cf240 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 48877964
...@@ -4,6 +4,14 @@ Zope Changes ...@@ -4,6 +4,14 @@ Zope Changes
Change information for previous versions of Zope can be found in the Change information for previous versions of Zope can be found in the
file HISTORY.txt. 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) Zope 2.10.0 (2006/10/04)
Bugs fixed Bugs fixed
......
...@@ -343,7 +343,7 @@ class HTTPResponse(BaseResponse): ...@@ -343,7 +343,7 @@ class HTTPResponse(BaseResponse):
self.setHeader('content-type', c) self.setHeader('content-type', c)
else: else:
c = self.headers['content-type'] 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) c = '%s; charset=%s' % (c, default_encoding)
self.setHeader('content-type', c) self.setHeader('content-type', c)
......
...@@ -94,11 +94,17 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -94,11 +94,17 @@ class HTTPResponseTests(unittest.TestCase):
self.assertEqual(response.headers.get('content-type'), self.assertEqual(response.headers.get('content-type'),
'text/plain; charset=iso-8859-15') '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', response = self._makeOne(body='foo',
headers={'content-type': 'application/foo'}) headers={'content-type': 'application/foo'})
self.assertEqual(response.headers.get('content-type'), 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): def test_charset_application_header_unicode(self):
response = self._makeOne(body=unicode('rger', 'iso-8859-15'), response = self._makeOne(body=unicode('rger', 'iso-8859-15'),
...@@ -117,9 +123,9 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -117,9 +123,9 @@ class HTTPResponseTests(unittest.TestCase):
def test_XMLEncodingRecoding(self): def test_XMLEncodingRecoding(self):
xml = u'<?xml version="1.0" encoding="iso-8859-15" ?>\n<foo><bar/></foo>' 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) 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) self.assertEqual(xml==response.body, True)
......
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