blivechat/api/base.py

22 lines
569 B
Python
Raw Normal View History

2019-06-12 13:55:49 +08:00
# -*- coding: utf-8 -*-
import json
2023-09-08 20:53:04 +08:00
from typing import *
2019-06-12 13:55:49 +08:00
import tornado.web
2023-09-08 20:53:04 +08:00
class ApiHandler(tornado.web.RequestHandler):
2021-07-17 13:03:45 +08:00
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
2023-09-08 20:53:04 +08:00
self.json_args: Optional[dict] = None
2021-07-17 13:03:45 +08:00
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