"Server": "TornadoServer/%s" % tornado.version,
"Content-Type": "text/html; charset=UTF-8",
}
+ self.set_default_headers()
if not self.request.supports_http_1_1():
if self.request.headers.get("Connection") == "Keep-Alive":
self.set_header("Connection", "Keep-Alive")
self._write_buffer = []
self._status_code = 200
+ def set_default_headers(self):
+ """Override this to set HTTP headers at the beginning of the request.
+
+ For example, this is the place to set a custom ``Server`` header.
+ 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.
+ """
+ pass
+
def set_status(self, status_code):
"""Sets the status code for our response."""
assert status_code in httplib.responses
``@authenticated`` decorator (default is in ``Application`` settings)
- ``get_template_path(self)`` - returns location of template files
(default is in ``Application`` settings)
+- ``set_default_headers(self)`` - may be used to set additional headers
+ on the response (such as a custom ``Server`` header)
Redirection
~~~~~~~~~~~
* In `tornado.web.Application`, handlers may be specified by
(fully-qualified) name instead of importing and passing the class object
itself.
+* `tornado.web.RequestHandler.set_default_headers` may be overridden to set
+ headers in a way that does not get reset during error handling.
Bug fixes
.. automethod:: RequestHandler.set_status
.. automethod:: RequestHandler.set_header
+ .. automethod:: RequestHandler.set_default_headers
.. automethod:: RequestHandler.write
.. automethod:: RequestHandler.flush
.. automethod:: RequestHandler.finish