Skip to content

Commit

Permalink
Merge pull request #21 from nvllsvm/ietf
Browse files Browse the repository at this point in the history
Support ietfparse 1.5.1
  • Loading branch information
nvllsvm committed Dec 4, 2018
2 parents 30a7360 + 5c7cebc commit b275c95
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion requires/installation.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ietfparse>=1.4,<1.5
ietfparse>=1.5.1,<2
tornado>=5,<6
6 changes: 6 additions & 0 deletions sprockets/mixins/mediatype/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ def get_response_content_type(self):
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

Expand All @@ -340,6 +343,9 @@ def get_request_body(self):
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:
Expand Down
22 changes: 22 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ def test_that_vary_header_is_set(self):
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):

Expand Down Expand Up @@ -135,6 +146,17 @@ def test_that_invalid_data_returns_400(self):
'</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):

Expand Down

0 comments on commit b275c95

Please sign in to comment.