diff --git a/Vagrantfile b/Vagrantfile index 2d91c67b80e8df2cf84b90e65f539bcaf7281f5f..fcb67e19bcd1929095e9722e0225b4aec7a5c653 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -16,7 +16,7 @@ Vagrant.configure("2") do |config| # Python apt-get install -y htop curl python3-pip build-essential python3 python3-setuptools - sudo pip3 install --upgrade pip setuptools + sudo pip3 install --upgrade pip setuptools Cython # Install deps sudo pip3 install -r /vagrant/requirements.txt diff --git a/flask_minijson.py b/flask_minijson.py index ea8ea4aed933b322b5a0bc945cea36e555bdf911..615b5b00d72832f76d74790e7304d3111ddd2881 100644 --- a/flask_minijson.py +++ b/flask_minijson.py @@ -10,13 +10,16 @@ except ImportError: from flask_json import FlaskJSONRequest as JsonRequest +MINIJSON_MIME = ('application/minijson', 'application/x-minijson') + + class MiniJSONRequest(JsonRequest): def get_json(self, force=False, silent=False, cache=True): """ Return JSON data, if content type is application/minijson it will be loaded via minijson, else it will be loaded the normal way. """ - if self.headers.get('Content-Type') == 'application/minijson': + if self.headers.get('Content-Type') in MINIJSON_MIME: return minijson.loads(self.get_data()) else: return super().get_json(force, silent, cache) diff --git a/setup.cfg b/setup.cfg index 8f03cf9b371a357a0d613d47e0420fd2aa51eb14..a8781f7505d2958f3a955138e9d74dab7a77db9f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ # coding: utf-8 [metadata] -version = 0.3 +version = 0.4 name = flask-minijson long_description = file: README.md long_description_content_type = text/markdown; charset=UTF-8 diff --git a/tests/test_minijson.py b/tests/test_minijson.py index bdbfe4ffdc8f759585a63b5fabce0ec5104d0813..b2fa4222d724ef272573114767bddc5d22ebf4e6 100644 --- a/tests/test_minijson.py +++ b/tests/test_minijson.py @@ -11,6 +11,8 @@ class TestMiniJSON(unittest.TestCase): def test_minijson(self): data = minijson.dumps({'1': '2'}) + resp = self.client.post('/v1', data=data, headers={'Content-Type': 'application/x-minijson'}) + self.assertEqual(resp.get_json(), {'status': 'ok'}) resp = self.client.post('/v1', data=data, headers={'Content-Type': 'application/minijson'}) self.assertEqual(resp.get_json(), {'status': 'ok'}) resp = self.client.post('/v1', json={'1': '3'})