From 808b72316a39d2c684213c622ae112dec777f887 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 13 Oct 2019 12:16:33 +0100 Subject: [PATCH] support application/json request body --- oml/oxtornado.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/oml/oxtornado.py b/oml/oxtornado.py index b34cdfe..23b4b91 100644 --- a/oml/oxtornado.py +++ b/oml/oxtornado.py @@ -83,9 +83,18 @@ class ApiHandler(tornado.web.RequestHandler): context = self._context if context is None: context = defaultcontext - action = request.arguments.get('action', [None])[0].decode('utf-8') - data = request.arguments.get('data', [b'{}'])[0] - data = json.loads(data.decode('utf-8')) if data else {} + action = None + if request.headers.get('Content-Type') == 'application/json': + try: + r = json.loads(request.body.decode()) + action = r['action'] + data = r['data'] + except: + action = None + if not action: + action = request.arguments.get('action', [None])[0].decode('utf-8') + data = request.arguments.get('data', [b'{}'])[0] + data = json.loads(data.decode('utf-8')) if data else {} if not action: methods = list(actions.keys()) api = []