fix(API): Always set the Vary header when serializing errors (#952)

This commit is contained in:
Kurt Griffiths
2017-01-24 08:14:34 -07:00
committed by Fran Fitzpatrick
parent f552316681
commit 1769092f21
2 changed files with 3 additions and 1 deletions

View File

@@ -123,7 +123,6 @@ def default_serialize_error(req, resp, exception):
preferred = 'application/xml'
if preferred is not None:
resp.append_header('Vary', 'Accept')
if preferred == 'application/json':
representation = exception.to_json()
else:
@@ -132,6 +131,8 @@ def default_serialize_error(req, resp, exception):
resp.body = representation
resp.content_type = preferred + '; charset=UTF-8'
resp.append_header('Vary', 'Accept')
def wrap_old_error_serializer(old_fn):
"""Wraps an old-style error serializer to add body/content_type setting.

View File

@@ -311,6 +311,7 @@ class TestHTTPError(testing.TestBase):
body = self.simulate_request('/fail', headers=headers)
self.assertEqual(self.srmock.status, headers['X-Error-Status'])
self.assertEqual(self.srmock.headers_dict['Vary'], 'Accept')
self.assertEqual(body, [])
def test_custom_old_error_serializer(self):