From 212dcb7876c75c36a95b6a8df4fd8d7b334dc6e9 Mon Sep 17 00:00:00 2001 From: Amber Heilman Date: Mon, 14 Sep 2015 11:13:07 -0400 Subject: [PATCH 1/2] default to the set content type default in settings --- sprockets/mixins/mediatype.py | 5 ++++- tests.py | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/sprockets/mixins/mediatype.py b/sprockets/mixins/mediatype.py index 9b06693..35a6702 100644 --- a/sprockets/mixins/mediatype.py +++ b/sprockets/mixins/mediatype.py @@ -178,7 +178,10 @@ class ContentMixin(object): if self._best_response_match is None: settings = ContentSettings.from_application(self.application) acceptable = headers.parse_http_accept_header( - self.request.headers.get('Accept', '*/*')) + self.request.headers.get( + 'Accept', + settings.default_content_type + if settings.default_content_type else '*/*')) try: selected, _ = algorithms.select_content_type( acceptable, settings.available_content_types) diff --git a/tests.py b/tests.py index e815601..dbea4b0 100644 --- a/tests.py +++ b/tests.py @@ -34,6 +34,13 @@ class SendResponseTests(testing.AsyncHTTPTestCase): self.assertEqual(response.headers['Content-Type'], 'application/msgpack') + def test_that_default_content_type_is_set_on_response(self): + response = self.fetch('/', method='POST', body=msgpack.packb('{}'), + headers={'Content-Type': 'application/msgpack'}) + self.assertEqual(response.code, 200) + self.assertEqual(response.headers['Content-Type'], + 'application/json; charset="utf-8"') + class GetRequestBodyTests(testing.AsyncHTTPTestCase): From 1a60c4a0f3bb15c1eac1762ffeda60eec4abd983 Mon Sep 17 00:00:00 2001 From: Amber Heilman Date: Mon, 14 Sep 2015 11:15:29 -0400 Subject: [PATCH 2/2] bump to 1.0.4 --- docs/history.rst | 6 ++++++ setup.py | 2 +- sprockets/mixins/mediatype.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/history.rst b/docs/history.rst index f0a32f9..7cd1220 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -1,6 +1,11 @@ Version History =============== +`1.0.4`_ (14 Sep 2015) +--------------------- +- Support using the default_content_type in the settings if request does not + contain the Accept header + `1.0.3`_ (10 Sep 2015) --------------------- - Update installation files @@ -17,6 +22,7 @@ Version History --------------------- - Initial Release +.. _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 diff --git a/setup.py b/setup.py index a5559c2..a7f374d 100755 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ tests_require = read_requirements('testing.txt') setuptools.setup( name='sprockets.mixins.mediatype', - version='1.0.3', + version='1.0.4', description='A mixin for reporting handling content-type/accept headers', long_description='\n' + open('README.rst').read(), url='https://github.com/sprockets/sprockets.mixins.media_type', diff --git a/sprockets/mixins/mediatype.py b/sprockets/mixins/mediatype.py index 35a6702..0a562d1 100644 --- a/sprockets/mixins/mediatype.py +++ b/sprockets/mixins/mediatype.py @@ -9,7 +9,7 @@ from ietfparse import algorithms, errors, headers from tornado import escape, web -version_info = (1, 0, 3) +version_info = (1, 0, 4) __version__ = '.'.join(str(v) for v in version_info) logger = logging.getLogger(__name__)