[Repoze-checkins] r1097 - in repoze.zope2/trunk: . repoze/zope2 repoze/zope2/tests

Chris McDonough chrism at agendaless.com
Mon Jun 16 16:56:19 EDT 2008


Author: Chris McDonough <chrism at agendaless.com>
Date: Mon Jun 16 16:56:19 2008
New Revision: 1097

Log:
  - Headers added to the response via "response.addHeaders" (aka
    accumulated_headers) were not returned in the response header
    list.




Modified:
   repoze.zope2/trunk/CHANGES.txt
   repoze.zope2/trunk/repoze/zope2/tests/base.py
   repoze.zope2/trunk/repoze/zope2/tests/test_z2bob.py
   repoze.zope2/trunk/repoze/zope2/z2bob.py

Modified: repoze.zope2/trunk/CHANGES.txt
==============================================================================
--- repoze.zope2/trunk/CHANGES.txt	(original)
+++ repoze.zope2/trunk/CHANGES.txt	Mon Jun 16 16:56:19 2008
@@ -3,6 +3,10 @@
   - Dont attempt any retries on conflict errors at startup.
     This was never tested, and probably didn't work.
 
+  - Headers added to the response via "response.addHeaders" (aka
+    accumulated_headers) were not returned in the response header
+    list.
+
 0.4.2 (2008-06-11)
 
   - Deal with Unauthorized exceptions properly: allow

Modified: repoze.zope2/trunk/repoze/zope2/tests/base.py
==============================================================================
--- repoze.zope2/trunk/repoze/zope2/tests/base.py	(original)
+++ repoze.zope2/trunk/repoze/zope2/tests/base.py	Mon Jun 16 16:56:19 2008
@@ -33,11 +33,13 @@
     urls_reset = False
     unauthorized_raises = None
     status = 200
+    accumulated_headers = ''
     def __init__(self):
         self.headers = {}
         self.cookies = {}
         self.ishtml = False
         self.stdout = StringIO()
+        
     def setCookie(self, name, value, **kw):
         name = str(name)
         value = str(value)

Modified: repoze.zope2/trunk/repoze/zope2/tests/test_z2bob.py
==============================================================================
--- repoze.zope2/trunk/repoze/zope2/tests/test_z2bob.py	(original)
+++ repoze.zope2/trunk/repoze/zope2/tests/test_z2bob.py	Mon Jun 16 16:56:19 2008
@@ -1028,6 +1028,21 @@
         response.headers['content-type'] = 'text/html'
         self.assertRaises(ValueError, helper.map_result, NotIterable)
 
+    def test_map_result_adds_accumulated_headers_to_headers(self):
+        helper = self._makeOne()
+        response = helper.request.response
+        response.accumulated_headers = 'Foo:bar\nFuz:baz\n'
+        status, headers, result = helper.map_result('foo')
+        self.assertEqual(len(headers), 4)
+        self.assertEqual(headers[0],
+                         ('Content-Length', '3'))
+        self.assertEqual(headers[1],
+                         ('Content-Type', 'text/plain; charset=utf-8'))
+        self.assertEqual(headers[2],
+                         ('Foo', 'bar'))
+        self.assertEqual(headers[3],
+                         ('Fuz', 'baz'))
+
     def test_handle_exception_reraises_unknown(self):
         helper = self._makeOne()
         class MyException(Exception):

Modified: repoze.zope2/trunk/repoze/zope2/z2bob.py
==============================================================================
--- repoze.zope2/trunk/repoze/zope2/z2bob.py	(original)
+++ repoze.zope2/trunk/repoze/zope2/z2bob.py	Mon Jun 16 16:56:19 2008
@@ -544,10 +544,21 @@
         cookies.sort()
         headers = response.headers.items()
         headers.sort()
-        headers = headers + cookies
+        accumulated_headers = self._getAccumulatedHeaders()
+        headers = headers + cookies + accumulated_headers
         httpheaders.normalize_headers(headers, strict=False)
         return headers
 
+    def _getAccumulatedHeaders(self):
+        accumulated_headers = self.request.response.accumulated_headers
+        L = []
+        more_headers = accumulated_headers.split('\n')
+        for line in more_headers:
+            if ':' in line:
+                name, value = [ x.strip() for x in line.split(':', 1) ]
+                L.append((name, value))
+        return L
+
     def _get_user(self):
         user = None
         request = self.request


More information about the Repoze-checkins mailing list