Skip to content

Commit

Permalink
Merge pull request #12 from sprockets/add-vary
Browse files Browse the repository at this point in the history
Set the Vary header.
  • Loading branch information
gmr committed Mar 14, 2016
2 parents 0c1c757 + a1cc214 commit 14f3533
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion docs/history.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions sprockets/mixins/mediatype/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,5 @@ def send_response(self, body, set_content_type=True):
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)
6 changes: 6 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ def test_that_default_content_type_is_set_on_response(self):
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):

Expand Down

0 comments on commit 14f3533

Please sign in to comment.