mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
Fixed #5956 -- Added a better error description for non-ASCII HTTP headers. Patch from jvloothuis.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6927 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -277,7 +277,20 @@ class HttpResponse(object):
|
||||
for key, value in self._headers.values()]) \
|
||||
+ '\n\n' + self.content
|
||||
|
||||
def _convert_to_ascii(self, *values):
|
||||
"Convert all values to ascii strings"
|
||||
for value in values:
|
||||
if isinstance(value, unicode):
|
||||
try:
|
||||
yield value.encode('us-ascii')
|
||||
except UnicodeError, e:
|
||||
e.reason += ', HTTP response headers must be in US-ASCII format'
|
||||
raise
|
||||
else:
|
||||
yield str(value)
|
||||
|
||||
def __setitem__(self, header, value):
|
||||
header, value = self._convert_to_ascii(header, value)
|
||||
self._headers[header.lower()] = (header, value)
|
||||
|
||||
def __delitem__(self, header):
|
||||
|
||||
Reference in New Issue
Block a user