Merge pull request #21 from nvllsvm/ietf

Support ietfparse 1.5.1
This commit is contained in:
Andrew Rabert 2018-12-04 16:59:45 -05:00 committed by GitHub
commit b275c95d39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

View file

@ -1,2 +1,2 @@
ietfparse>=1.4,<1.5
ietfparse>=1.5.1,<2
tornado>=5,<6

View file

@ -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:

View file

@ -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):