Commits

ianb  committed 85a0ab5

Fix #251, encode response headers

  • Participants
  • Parent commits d41f941

Comments (0)

Files changed (3)

File docs/news.txt

 
 .. contents::
 
-svn trunk
----------
+0.9.1
+-----
 
 * ``request.params.copy()`` now returns a writable MultiDict (before
   it returned an unwritable object).
   used to construct ``Request`` (e.g., ``Request.blank('/',
   decode_param_names=True)``).
 
+* If you set headers like ``response.etag`` to a unicode value, they
+  will be encoded as ISO-8859-1 (however, they will remain encoded,
+  and ``response.etag`` will not be a unicode value).
+
 0.9
 ---
 

File tests/test_response.txt

     >>> res = exc.HTTPNotModified()
     >>> res.headers
     HeaderDict([])
+
+Headers can be set to unicode values::
+
+    >>> res = Response('test')
+    >>> res.etag = u'fran\xe7ais'
+
+But they come out as str::
+
+    >>> res.etag
+    'fran\xe7ais'

File webob/__init__.py

             if self.header in obj.headers:
                 del obj.headers[self.header]
         else:
+            if isinstance(value, unicode):
+                # This is the standard encoding for headers:
+                value = value.encode('ISO-8859-1')
             obj.headers[self.header] = value
 
     def __delete__(self, obj):