[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.
--- a/web/request.py Tue Feb 23 12:09:01 2016 +0100
+++ b/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/web/test/unittest_http.py Tue Feb 23 12:09:01 2016 +0100
+++ b/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):