Commit 7596da86 authored by Andreas Jung's avatar Andreas Jung

more tests and fixes

parent 14923f9b
......@@ -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,
......
# -*- coding: iso-8859-15 -*-
import unittest
class HTTPResponseTests(unittest.TestCase):
......@@ -74,6 +76,27 @@ 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_CharsetApplicationHeaderUnicode(self):
response = self._makeOne(body=unicode('rger', 'iso-8859-15'), headers={'content-type': 'application/foo'})
self.assertEqual(response.headers.get('content-type'), 'application/foo; charset=iso-8859-15')
self.assertEqual(response.body, 'rger')
def test_CharsetApplicationHeader1Unicode(self):
response = self._makeOne(body=unicode('rger', 'iso-8859-15'), headers={'content-type': 'application/foo; charset=utf-8'})
self.assertEqual(response.headers.get('content-type'), 'application/foo; charset=utf-8')
self.assertEqual(response.body, unicode('rger', 'iso-8859-15').encode('utf-8'))
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