pyramid_cubicweb/core.py
changeset 11556 1eeba41a2e95
parent 11553 a322a02ca301
child 11560 1a816189ceee
--- a/pyramid_cubicweb/core.py	Tue Feb 10 10:23:20 2015 +0100
+++ b/pyramid_cubicweb/core.py	Tue Feb 10 16:35:06 2015 +0100
@@ -1,3 +1,5 @@
+import itertools
+
 from contextlib import contextmanager
 from warnings import warn
 from cgi import FieldStorage
@@ -70,6 +72,12 @@
             self._protect_data_access = False
 
 
+def cw_headers(request):
+    return itertools.chain(
+        *[[(k, item) for item in v]
+          for k, v in request.cw_request.headers_out.getAllRawHeaders()])
+
+
 @contextmanager
 def cw_to_pyramid(request):
     """ Context manager to wrap a call to the cubicweb API.
@@ -80,7 +88,8 @@
         yield
     except cubicweb.web.Redirect as ex:
         assert 300 <= ex.status < 400
-        raise httpexceptions.status_map[ex.status](ex.location)
+        raise httpexceptions.status_map[ex.status](
+            ex.location, headers=cw_headers(request))
     except cubicweb.web.StatusResponse as ex:
         warn('[3.16] StatusResponse is deprecated use req.status_out',
              DeprecationWarning, stacklevel=2)
@@ -91,13 +100,15 @@
             request.cw_request._(
                 'You\'re not authorized to access this page. '
                 'If you think you should, please contact the site '
-                'administrator.'))
+                'administrator.'),
+            headers=cw_headers(request))
     except cubicweb.web.Forbidden:
         raise httpexceptions.HTTPForbidden(
             request.cw_request._(
                 'This action is forbidden. '
                 'If you think it should be allowed, please contact the site '
-                'administrator.'))
+                'administrator.'),
+            headers=cw_headers(request))
     except (rql.BadRQLQuery, cubicweb.web.RequestError) as ex:
         raise