summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/news.txt6
-rw-r--r--paste/response.py6
-rw-r--r--paste/wsgiwrappers.py21
3 files changed, 26 insertions, 7 deletions
diff --git a/docs/news.txt b/docs/news.txt
index 7633544..0d354a0 100644
--- a/docs/news.txt
+++ b/docs/news.txt
@@ -3,6 +3,12 @@ News
.. contents::
+0.9.9
+-----
+
+* Fixed ``paste.response.HeaderDict`` ``get`` and ``setdefault``
+ methods to be case insensitive
+
0.9.8
-----
diff --git a/paste/response.py b/paste/response.py
index fb003cb..fd4acf5 100644
--- a/paste/response.py
+++ b/paste/response.py
@@ -40,6 +40,12 @@ class HeaderDict(dict):
has_key = __contains__
+ def get(self, key, failobj=None):
+ return dict.get(self, self.normalize(key), failobj)
+
+ def setdefault(self, key, failobj=None):
+ return dict.setdefault(self, self.normalize(key), failobj)
+
def pop(self, key):
return dict.pop(self, self.normalize(key))
diff --git a/paste/wsgiwrappers.py b/paste/wsgiwrappers.py
index 1063988..ab33098 100644
--- a/paste/wsgiwrappers.py
+++ b/paste/wsgiwrappers.py
@@ -140,13 +140,9 @@ class WSGIResponse(object):
self.headers = HeaderDict()
self.cookies = SimpleCookie()
self.status_code = code
- self.encoding = settings['charset']
if not mimetype:
- mimetype = "%s; charset=%s" % (settings['content_type'], settings['charset'])
- else:
- charset_match = _CHARSET_RE.match(mimetype)
- if charset_match:
- self.encoding = charset_match.group(1)
+ mimetype = "%s; charset=%s" % (settings['content_type'],
+ settings['charset'])
self.headers['Content-Type'] = mimetype
if 'encoding_errors' in settings:
@@ -168,6 +164,17 @@ class WSGIResponse(object):
return '\n'.join(['%s: %s' % (key, value)
for key, value in self.headers.headeritems()]) \
+ '\n\n' + content
+
+ def determine_encoding(self):
+ """
+ Determine the encoding as specified by the Content-Type's charset
+ parameter, if one is set
+ """
+ charset_match = _CHARSET_RE.match(self.headers.get('Content-Type', ''))
+ if charset_match:
+ return charset_match.group(1)
+ # No charset specified, default to iso-8859-1 as per RFC2616
+ return 'iso-8859-1'
def has_header(self, header):
"""
@@ -224,7 +231,7 @@ class WSGIResponse(object):
Returns the content as an iterable of strings, encoding each element of
the iterator from a Unicode object if necessary.
"""
- return encode_unicode_app_iter(self.content, self.encoding,
+ return encode_unicode_app_iter(self.content, self.determine_encoding(),
self.encoding_errors)
def wsgi_response(self):