From 212dcb7876c75c36a95b6a8df4fd8d7b334dc6e9 Mon Sep 17 00:00:00 2001 From: Amber Heilman Date: Mon, 14 Sep 2015 11:13:07 -0400 Subject: [PATCH] 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):