Commit 77a95049 authored by Andreas Jung's avatar Andreas Jung

fixes + more tests (Stefan Holek)

parent 6764040e
......@@ -333,13 +333,18 @@ class HTTPResponse(BaseResponse):
self.body = body
if not self.headers.has_key('content-type'):
isHTML = self.isHTML(self.body)
if not self.headers.has_key('content-type'):
if isHTML:
c = 'text/html; charset=%s' % default_encoding
else:
c = 'text/plain; charset=%s' % default_encoding
self.setHeader('content-type', c)
else:
c = self.headers['content-type']
if not 'charset=' in c:
c = '%s; charset=%s' % (c, default_encoding)
self.setHeader('content-type', c)
# Some browsers interpret certain characters in Latin 1 as html
# special characters. These cannot be removed by html_quote,
......
......@@ -74,6 +74,17 @@ class HTTPResponseTests(unittest.TestCase):
response.appendHeader('XXX', 'foo')
self.assertEqual(response.headers.get('xxx'), 'bar,\n\tfoo')
def test_CharsetNoHeader(self):
response = self._makeOne(body='foo')
self.assertEqual(response.headers.get('content-type'), 'text/plain; charset=iso-8859-15')
def test_CharsetTextHeader(self):
response = self._makeOne(body='foo', headers={'content-type': 'text/plain'})
self.assertEqual(response.headers.get('content-type'), 'text/plain; charset=iso-8859-15')
def test_CharsetApplicationHeader(self):
response = self._makeOne(body='foo', headers={'content-type': 'application/foo'})
self.assertEqual(response.headers.get('content-type'), 'application/foo; charset=iso-8859-15')
def test_suite():
suite = unittest.TestSuite()
......
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