diff --git a/docs/history.rst b/docs/history.rst index aaf132c..1d94bca 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -1,6 +1,10 @@ Version History =============== +`Next Release`_ +--------------- +- Set the _`Vary` header if we are setting the content type. + `2.0.1`_ (29 Feb 2016) ---------------------- - Removed deprecation wrapper since it seems to cause really interesting @@ -38,10 +42,13 @@ Version History --------------------- - Initial Release -.. _Next Release: https://github.com/sprockets/sprockets.http/compare/2.0.0...HEAD +.. _Next Release: https://github.com/sprockets/sprockets.http/compare/2.0.1...HEAD +.. _2.0.1: https://github.com/sprockets/sprockets.http/compare/2.0.0...2.0.1 .. _2.0.0: https://github.com/sprockets/sprockets.http/compare/1.0.4...2.0.0 .. _1.0.4: https://github.com/sprockets/sprockets.http/compare/1.0.3...1.0.4 .. _1.0.3: https://github.com/sprockets/sprockets.http/compare/1.0.2...1.0.3 .. _1.0.2: https://github.com/sprockets/sprockets.http/compare/1.0.1...1.0.2 .. _1.0.1: https://github.com/sprockets/sprockets.http/compare/1.0.0...1.0.1 .. _1.0.0: https://github.com/sprockets/sprockets.http/compare/0.0.0...1.0.0 + +.. _Vary: http://tools.ietf.org/html/rfc7234#section-4.1 diff --git a/sprockets/mixins/mediatype/content.py b/sprockets/mixins/mediatype/content.py index 73dc0ef..430552a 100644 --- a/sprockets/mixins/mediatype/content.py +++ b/sprockets/mixins/mediatype/content.py @@ -303,4 +303,5 @@ class ContentMixin(object): content_type, data_bytes = handler.to_bytes(body) if set_content_type: self.set_header('Content-Type', content_type) + self.add_header('Vary', 'Accept') self.write(data_bytes) diff --git a/tests.py b/tests.py index 76cb2a4..192f4da 100644 --- a/tests.py +++ b/tests.py @@ -95,6 +95,12 @@ class SendResponseTests(testing.AsyncHTTPTestCase): self.assertEqual(response.headers['Content-Type'], 'application/json; charset="utf-8"') + def test_that_vary_header_is_set(self): + response = self.fetch('/', method='POST', body=umsgpack.packb({}), + headers={'Content-Type': 'application/msgpack'}) + self.assertEqual(response.code, 200) + self.assertEqual(response.headers['Vary'], 'Accept') + class GetRequestBodyTests(testing.AsyncHTTPTestCase):