summaryrefslogtreecommitdiff
path: root/django/http
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2013-10-17 18:07:47 +0200
committerClaude Paroz <claude@2xlibre.net>2013-10-17 18:15:56 +0200
commitb2f9c74ed1cd246022ab52d239eeb33f950dcc70 (patch)
tree9f0a0897440b704ec7d45ea1f2b3a0cb695e65c7 /django/http
parent1241a2cc104d092ff0f03a16a664e9e4ab801dd1 (diff)
[1.6.x] Fixed #21282 -- Made HttpResponse.serialize_headers accept latin-1
Thanks Raphaƫl Barrois for the report and the initial patch and Aymeric Augustin for the review. Backport of a14f087233 from master.
Diffstat (limited to 'django/http')
-rw-r--r--django/http/response.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/django/http/response.py b/django/http/response.py
index f522c0684b..83b01831b5 100644
--- a/django/http/response.py
+++ b/django/http/response.py
@@ -128,8 +128,11 @@ class HttpResponseBase(six.Iterator):
def serialize_headers(self):
"""HTTP headers as a bytestring."""
+ def to_bytes(val, encoding):
+ return val if isinstance(val, bytes) else val.encode(encoding)
+
headers = [
- ('%s: %s' % (key, value)).encode('us-ascii')
+ (b': '.join([to_bytes(key, 'ascii'), to_bytes(value, 'latin-1')]))
for key, value in self._headers.values()
]
return b'\r\n'.join(headers)
@@ -140,7 +143,7 @@ class HttpResponseBase(six.Iterator):
__str__ = serialize_headers
def _convert_to_charset(self, value, charset, mime_encode=False):
- """Converts headers key/value to ascii/latin1 native strings.
+ """Converts headers key/value to ascii/latin-1 native strings.
`charset` must be 'ascii' or 'latin-1'. If `mime_encode` is True and
`value` value can't be represented in the given charset, MIME-encoding
@@ -176,7 +179,7 @@ class HttpResponseBase(six.Iterator):
def __setitem__(self, header, value):
header = self._convert_to_charset(header, 'ascii')
- value = self._convert_to_charset(value, 'latin1', mime_encode=True)
+ value = self._convert_to_charset(value, 'latin-1', mime_encode=True)
self._headers[header.lower()] = (header, value)
def __delitem__(self, header):