[web] fix headers on 304 responses (closes #11466875)
authorJulien Cristau <julien.cristau@logilab.fr>
Thu, 10 Mar 2016 13:47:20 +0100
changeset 11174 eb88fdfd3740
parent 11173 9441ebb30dd6
child 11175 df979f327e3f
[web] fix headers on 304 responses (closes #11466875) The response MUST include the following header fields: [...] - ETag and/or Content-Location, if the header would have been sent in a 200 response to the same request https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5 Unfortunately we weren't copying headers from what would have been the 200 response, but from the request.
cubicweb/web/request.py
cubicweb/web/test/unittest_http.py
--- a/cubicweb/web/request.py	Wed Mar 09 18:01:44 2016 +0100
+++ b/cubicweb/web/request.py	Thu Mar 10 13:47:20 2016 +0100
@@ -746,7 +746,7 @@
             'cache-control', 'vary',
             # Others:
             'server', 'proxy-authenticate', 'www-authenticate', 'warning'):
-            value = self._headers_in.getRawHeaders(header)
+            value = self.headers_out.getRawHeaders(header)
             if value is not None:
                 headers.setRawHeaders(header, value)
         return headers
--- a/cubicweb/web/test/unittest_http.py	Wed Mar 09 18:01:44 2016 +0100
+++ b/cubicweb/web/test/unittest_http.py	Thu Mar 10 13:47:20 2016 +0100
@@ -152,6 +152,7 @@
                ]
         req = _test_cache(hin, hout)
         self.assertCache(304, req.status_out, 'etag match')
+        self.assertEqual(req.headers_out.getRawHeaders('etag'), ['babar'])
         # etag match in multiple
         hin  = [('if-none-match', 'loutre'),
                 ('if-none-match', 'babar'),
@@ -160,6 +161,7 @@
                ]
         req = _test_cache(hin, hout)
         self.assertCache(304, req.status_out, 'etag match in multiple')
+        self.assertEqual(req.headers_out.getRawHeaders('etag'), ['babar'])
         # client use "*" as etag
         hin  = [('if-none-match', '*'),
                ]
@@ -167,6 +169,7 @@
                ]
         req = _test_cache(hin, hout)
         self.assertCache(304, req.status_out, 'client use "*" as etag')
+        self.assertEqual(req.headers_out.getRawHeaders('etag'), ['babar'])
 
     @tag('etag', 'last_modified')
     def test_both(self):
@@ -216,6 +219,7 @@
                ]
         req = _test_cache(hin, hout)
         self.assertCache(304, req.status_out, 'both ok')
+        self.assertEqual(req.headers_out.getRawHeaders('etag'), ['babar'])
 
     @tag('etag', 'HEAD')
     def test_head_verb(self):
@@ -235,6 +239,7 @@
                ]
         req = _test_cache(hin, hout, method='HEAD')
         self.assertCache(304, req.status_out, 'not modifier HEAD verb')
+        self.assertEqual(req.headers_out.getRawHeaders('etag'), ['babar'])
 
     @tag('etag', 'POST')
     def test_post_verb(self):