mirror of
https://github.com/sprockets/sprockets.mixins.mediatype.git
synced 2024-12-29 11:17:10 +00:00
commit
b275c95d39
3 changed files with 29 additions and 1 deletions
|
@ -1,2 +1,2 @@
|
|||
ietfparse>=1.4,<1.5
|
||||
ietfparse>=1.5.1,<2
|
||||
tornado>=5,<6
|
||||
|
|
|
@ -317,6 +317,9 @@ class ContentMixin:
|
|||
acceptable, settings.available_content_types)
|
||||
self._best_response_match = '/'.join(
|
||||
[selected.content_type, selected.content_subtype])
|
||||
if selected.content_suffix is not None:
|
||||
self._best_response_match = '+'.join(
|
||||
[self._best_response_match, selected.content_suffix])
|
||||
except errors.NoMatch:
|
||||
self._best_response_match = settings.default_content_type
|
||||
|
||||
|
@ -340,6 +343,9 @@ class ContentMixin:
|
|||
settings.default_content_type))
|
||||
content_type = '/'.join([content_type_header.content_type,
|
||||
content_type_header.content_subtype])
|
||||
if content_type_header.content_suffix is not None:
|
||||
content_type = '+'.join([content_type,
|
||||
content_type_header.content_suffix])
|
||||
try:
|
||||
handler = settings[content_type]
|
||||
except KeyError:
|
||||
|
|
22
tests.py
22
tests.py
|
@ -101,6 +101,17 @@ class SendResponseTests(testing.AsyncHTTPTestCase):
|
|||
self.assertEqual(response.code, 200)
|
||||
self.assertEqual(response.headers['Vary'], 'Accept')
|
||||
|
||||
def test_that_accept_header_with_suffix_is_obeyed(self):
|
||||
content.add_transcoder(
|
||||
self._app,
|
||||
transcoders.MsgPackTranscoder(content_type='expected/content'),
|
||||
'application/vendor+msgpack')
|
||||
response = self.fetch('/', method='POST', body='{}',
|
||||
headers={'Accept': 'application/vendor+msgpack',
|
||||
'Content-Type': 'application/json'})
|
||||
self.assertEqual(response.code, 200)
|
||||
self.assertEqual(response.headers['Content-Type'], 'expected/content')
|
||||
|
||||
|
||||
class GetRequestBodyTests(testing.AsyncHTTPTestCase):
|
||||
|
||||
|
@ -135,6 +146,17 @@ class GetRequestBodyTests(testing.AsyncHTTPTestCase):
|
|||
'</param></params></methodCall>').encode('utf-8'))
|
||||
self.assertEqual(response.code, 400)
|
||||
|
||||
def test_that_content_type_suffix_is_handled(self):
|
||||
content.add_transcoder(
|
||||
self._app, transcoders.JSONTranscoder(),
|
||||
'application/vendor+json')
|
||||
body = {'hello': 'world'}
|
||||
response = self.fetch(
|
||||
'/', method='POST', body=json.dumps(body),
|
||||
headers={'Content-Type': 'application/vendor+json'})
|
||||
self.assertEqual(response.code, 200)
|
||||
self.assertEqual(json.loads(response.body.decode()), body)
|
||||
|
||||
|
||||
class JSONTranscoderTests(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Reference in a new issue