]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add RequestHandler.set_default_headers, which may be overridden to set
authorBen Darnell <ben@bendarnell.com>
Mon, 4 Jul 2011 17:17:32 +0000 (10:17 -0700)
committerBen Darnell <ben@bendarnell.com>
Mon, 4 Jul 2011 17:19:54 +0000 (10:19 -0700)
headers that will not be reset during error handling.

tornado/web.py
website/sphinx/overview.rst
website/sphinx/releases/next.rst
website/sphinx/web.rst

index 205cf645cb9edb6954efe0ac757da2446faf1b06..648c5cc79cae5821177a6bec95e38bf9891ab9b2 100644 (file)
@@ -186,12 +186,23 @@ class RequestHandler(object):
             "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
index c33e49933993a4691bacd5ed9abeb3552c858d33..0efb453abe446d9fc210e26425d23611e0a45e1b 100644 (file)
@@ -166,6 +166,8 @@ Other methods designed for overriding include:
    ``@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
 ~~~~~~~~~~~
index f9d56abaa0d5acaf268525eb8945a34ee705c5ee..9b5166fd685feb255a4761c0e667c6e09726b430 100644 (file)
@@ -36,6 +36,8 @@ New features
 * 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
index fd1af5b8735865f0bd00cf7d19b3fa48064c237a..2840c240a22489890be2bbdb0c0f61cc08745e07 100644 (file)
@@ -39,6 +39,7 @@
 
    .. automethod:: RequestHandler.set_status
    .. automethod:: RequestHandler.set_header
+   .. automethod:: RequestHandler.set_default_headers
    .. automethod:: RequestHandler.write
    .. automethod:: RequestHandler.flush
    .. automethod:: RequestHandler.finish