Search code examples
tornado

how to disable tornado return 200 in an empty handler


class MainHandler(tornado.web.RequestHandler):
    @tornado.web.asynchronous
    @tornado.gen.coroutine
    def post(self):
        pass

I found tornado will return 200 in this case
How can I disable it.


Solution

  • To clarify, Tornado will use 200 if response code is not explicitly set, or error occurred. It would be hard to find out that method is "empty" - only pass, without inspecting traceback, that is overkill IMHO.

    So either you set status code in the method

    class MainHandler(tornado.web.RequestHandler):
    
        @tornado.gen.coroutine
        def post(self):
            self.set_status(501, 'Not implemented')
    

    or remove entirelypost method if it isn't used, client will receive 405 Method Not Allowed.