blivechat/api/base.py

21 lines
540 B
Python
Raw Normal View History

2019-06-12 13:55:49 +08:00
# -*- coding: utf-8 -*-
import json
import tornado.web
2022-02-15 00:18:46 +08:00
class ApiHandler(tornado.web.RequestHandler): # noqa
2021-07-17 13:03:45 +08:00
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.json_args = None
2019-06-12 13:55:49 +08:00
def prepare(self):
self.set_header('Cache-Control', 'no-cache')
2021-07-17 13:03:45 +08:00
if not self.request.headers.get('Content-Type', '').startswith('application/json'):
return
try:
self.json_args = json.loads(self.request.body)
except json.JSONDecodeError:
pass