[bwcompat] set response headers on AuthenticationError (closes #12219860)
authorJulien Cristau <julien.cristau@logilab.fr>
Fri, 01 Apr 2016 16:48:14 +0200
changeset 11614 171e70a7b121
parent 11613 08afd21f17f6
child 11615 7e798fe70014
[bwcompat] set response headers on AuthenticationError (closes #12219860) Turns out sending a response without a Content-Type header (among others) is suboptimal. 5b36399b6b21 was not good enough.
pyramid_cubicweb/bwcompat.py
--- a/pyramid_cubicweb/bwcompat.py	Thu Mar 24 12:08:59 2016 +0100
+++ b/pyramid_cubicweb/bwcompat.py	Fri Apr 01 16:48:14 2016 +0200
@@ -95,13 +95,6 @@
                 # for this exception) should be enough
                 # content = self.appli.ajax_error_handler(req, ex)
                 raise
-            finally:
-                # XXX CubicWebPyramidRequest.headers_out should
-                # access directly the pyramid response headers.
-                request.response.headers.clear()
-                for k, v in req.headers_out.getAllRawHeaders():
-                    for item in v:
-                        request.response.headers.add(k, item)
 
             if content is not None:
                 request.response.body = content
@@ -118,6 +111,13 @@
             if not content:
                 content = vreg['views'].main_template(req, 'login')
                 request.response.body = content
+        finally:
+            # XXX CubicWebPyramidRequest.headers_out should
+            # access directly the pyramid response headers.
+            request.response.headers.clear()
+            for k, v in req.headers_out.getAllRawHeaders():
+                for item in v:
+                    request.response.headers.add(k, item)
 
         return request.response