mirror of
https://github.com/sprockets/sprockets.mixins.mediatype.git
synced 2024-12-29 11:17:10 +00:00
Merge pull request #4 from sprockets/add-default-content-type-to-resp
default to the set content type default in settings
This commit is contained in:
commit
d60ca0966a
4 changed files with 19 additions and 3 deletions
|
@ -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
|
||||
|
|
2
setup.py
2
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',
|
||||
|
|
|
@ -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__)
|
||||
|
||||
|
@ -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)
|
||||
|
|
7
tests.py
7
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):
|
||||
|
||||
|
|
Loading…
Reference in a new issue