Skip to content

Commit

Permalink
Merge pull request #4 from sprockets/add-default-content-type-to-resp
Browse files Browse the repository at this point in the history
default to the set content type default in settings
  • Loading branch information
dave-shawley committed Sep 27, 2015
2 parents ebf8fe4 + 1a60c4a commit d60ca09
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def read_requirements(file_name):

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',
Expand Down
7 changes: 5 additions & 2 deletions sprockets/mixins/mediatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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__)

Expand Down Expand Up @@ -178,7 +178,10 @@ def get_response_content_type(self):
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)
Expand Down
7 changes: 7 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ def test_that_accept_header_is_obeyed(self):
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):

Expand Down

0 comments on commit d60ca09

Please sign in to comment.