Answer the question
In order to leave comments, you need to log in
Why is tornado blocking headers?
It is necessary to throw Authorization with a certain key in the headers. If you set the headers directly through the options and set_default_headers methods, then everything is ok. But there are more than 100 handlers in the code, and it’s not comme il faut to hang up your own options for each.
This is how it works
class LongPollingHandler(tornado.web.RequestHandler):
def set_default_headers(self):
self.set_header("Access-Control-Allow-Origin", "*")
def options(self, *args, **kwargs):
self.set_header("Access-Control-Allow-Headers", "*")
self.set_header('Access-Control-Allow-Methods', '*')
async def get(self):
pass
class BaseHandler(tornado.web.RequestHandler):
def set_default_headers(self):
self.set_header("Access-Control-Allow-Origin", "*")
def options(self, *args, **kwargs):
self.set_header("Access-Control-Allow-Headers", "*")
self.set_header('Access-Control-Allow-Methods', '*')
def prepare(self):
if db.is_closed():
db.connect()
return super(BaseHandler, self).prepare()
def on_finish(self):
if not db.is_closed():
db.close()
return super(BaseHandler, self).on_finish()
class LongPollingHandler(BaseHandler):
pass
Answer the question
In order to leave comments, you need to log in
class BaseHandler(tornado.web.RequestHandler):
def set_default_headers(self):
self.set_header('Access-Control-Allow-Origin', '*')
def options(self, *args, **kwargs):
self.set_header('Access-Control-Allow-Headers', '*')
self.set_header('Access-Control-Allow-Methods', '*')
self.set_status(204)
self.finish()
class LongPollingHandler(BaseHandler):
def get(self, status):
self.write('{"data": "Hello"}')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question