diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-12-17 08:05:51 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-12-17 08:05:51 +0000 |
| commit | 03f1eb23e5c39e130744f885d480b2aa70d93088 (patch) | |
| tree | d58226413fb401969b1cc49128bcab2ce72229b5 /django/http | |
| parent | 1fcb4e4bcdb99b44561b7b70c1563e059daadbd2 (diff) | |
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
Diffstat (limited to 'django/http')
| -rw-r--r-- | django/http/__init__.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/django/http/__init__.py b/django/http/__init__.py index 13cc8cea0d..69e9d51204 100644 --- a/django/http/__init__.py +++ b/django/http/__init__.py @@ -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): |
