diff --git a/django/http/response.py b/django/http/response.py
index f522c06..4198360 100644
a
|
b
|
class HttpResponseBase(six.Iterator):
|
129 | 129 | def serialize_headers(self): |
130 | 130 | """HTTP headers as a bytestring.""" |
131 | 131 | headers = [ |
132 | | ('%s: %s' % (key, value)).encode('us-ascii') |
| 132 | (b'%s: %s' % (key, value)) |
133 | 133 | for key, value in self._headers.values() |
134 | 134 | ] |
135 | 135 | return b'\r\n'.join(headers) |
diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py
index 7eb11b1..e82a7e2 100644
a
|
b
|
class HttpResponseTests(unittest.TestCase):
|
417 | 417 | self.assertRaises(SuspiciousOperation, |
418 | 418 | HttpResponsePermanentRedirect, url) |
419 | 419 | |
| 420 | def test_header_value_encoding(self): |
| 421 | """Test encoding of header values.""" |
| 422 | r = HttpResponse() |
| 423 | r['ascii'] = "no_special_chars" |
| 424 | r['latin1'] = "blé" # latin1-compatible text |
| 425 | r['utf8'] = "Føŧ" # Non-latin1-compatible, will be mime-encoded |
| 426 | serialized = r.serialize_headers() |
| 427 | header_lines = serialized.split(b'\r\n') |
| 428 | self.assertIn(b'ascii: no_special_chars', header_lines) |
| 429 | self.assertIn(b'latin1: bl\xe9', header_lines) |
| 430 | self.assertIn(b'utf8: =?utf-8?b?RsO4xac=?=', header_lines) |
| 431 | |
| 432 | |
420 | 433 | class HttpResponseSubclassesTests(TestCase): |
421 | 434 | def test_redirect(self): |
422 | 435 | response = HttpResponseRedirect('/redirected/') |