support application/json request body
This commit is contained in:
parent
14c8345740
commit
808b72316a
1 changed files with 12 additions and 3 deletions
|
@ -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 = []
|
||||
|
|
Loading…
Reference in a new issue