How can I set custom Server header with Tornado?

Viewed 1826

I noticed that my app returns this HTTP response header:

Server: TornadoServer/4.5.2

Is it possible to change it to custom?

3 Answers

Use RequestHandler.set_default_headers()

Do note that setting such headers in the normal flow of request processing may not do what you want, since headers may be reset during error handling.

Here is the source from the documentation.

You can use the RequestHandler.set_header() for the headers you want to add or change. Here is an example

    RequestHandler.set_header('Access-Control-Allow-Origin', '*')
    RequestHandler.set_header('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS')
    RequestHandler.set_header('Access-Control-Max-Age', 1000)

you also can use RequestHandler.set_header().

this method will change the finally return response header.

Related