fix(API): Always set the Vary header when serializing errors (#952)
This commit is contained in:
committed by
Fran Fitzpatrick
parent
f552316681
commit
1769092f21
@@ -123,7 +123,6 @@ def default_serialize_error(req, resp, exception):
|
|||||||
preferred = 'application/xml'
|
preferred = 'application/xml'
|
||||||
|
|
||||||
if preferred is not None:
|
if preferred is not None:
|
||||||
resp.append_header('Vary', 'Accept')
|
|
||||||
if preferred == 'application/json':
|
if preferred == 'application/json':
|
||||||
representation = exception.to_json()
|
representation = exception.to_json()
|
||||||
else:
|
else:
|
||||||
@@ -132,6 +131,8 @@ def default_serialize_error(req, resp, exception):
|
|||||||
resp.body = representation
|
resp.body = representation
|
||||||
resp.content_type = preferred + '; charset=UTF-8'
|
resp.content_type = preferred + '; charset=UTF-8'
|
||||||
|
|
||||||
|
resp.append_header('Vary', 'Accept')
|
||||||
|
|
||||||
|
|
||||||
def wrap_old_error_serializer(old_fn):
|
def wrap_old_error_serializer(old_fn):
|
||||||
"""Wraps an old-style error serializer to add body/content_type setting.
|
"""Wraps an old-style error serializer to add body/content_type setting.
|
||||||
|
|||||||
@@ -311,6 +311,7 @@ class TestHTTPError(testing.TestBase):
|
|||||||
|
|
||||||
body = self.simulate_request('/fail', headers=headers)
|
body = self.simulate_request('/fail', headers=headers)
|
||||||
self.assertEqual(self.srmock.status, headers['X-Error-Status'])
|
self.assertEqual(self.srmock.status, headers['X-Error-Status'])
|
||||||
|
self.assertEqual(self.srmock.headers_dict['Vary'], 'Accept')
|
||||||
self.assertEqual(body, [])
|
self.assertEqual(body, [])
|
||||||
|
|
||||||
def test_custom_old_error_serializer(self):
|
def test_custom_old_error_serializer(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user