Subclass this class and define get() or post() to make a handler. If you want to support more methods than the standard GET/HEAD/POST, you should override the class variable SUPPORTED_METHODS in your RequestHandler class.
def tornado.web.RequestHandler.__init__ | ( | self, | |
application, | |||
request, | |||
kwargs | |||
) |
Reimplemented in tornado.websocket.WebSocketHandler.
def tornado.web.RequestHandler._clear_headers_for_304 | ( | self | ) | [private] |
def tornado.web.RequestHandler._convert_header_value | ( | self, | |
value | |||
) | [private] |
def tornado.web.RequestHandler._execute | ( | self, | |
transforms, | |||
args, | |||
kwargs | |||
) | [private] |
Executes this request with the given output transforms.
Reimplemented in tornado.websocket.WebSocketHandler.
def tornado.web.RequestHandler._generate_headers | ( | self | ) | [private] |
def tornado.web.RequestHandler._handle_request_exception | ( | self, | |
e | |||
) | [private] |
def tornado.web.RequestHandler._log | ( | self | ) | [private] |
def tornado.web.RequestHandler._request_summary | ( | self | ) | [private] |
def tornado.web.RequestHandler._stack_context_handle_exception | ( | self, | |
type, | |||
value, | |||
traceback | |||
) | [private] |
def tornado.web.RequestHandler._ui_method | ( | self, | |
method | |||
) | [private] |
def tornado.web.RequestHandler._ui_module | ( | self, | |
name, | |||
module | |||
) | [private] |
def tornado.web.RequestHandler.add_header | ( | self, | |
name, | |||
value | |||
) |
def tornado.web.RequestHandler.async_callback | ( | self, | |
callback, | |||
args, | |||
kwargs | |||
) |
Obsolete - catches exceptions from the wrapped function. This function is unnecessary since Tornado 1.1.
Reimplemented in tornado.websocket.WebSocketHandler.
def tornado.web.RequestHandler.check_xsrf_cookie | ( | self | ) |
Verifies that the '_xsrf' cookie matches the '_xsrf' argument. To prevent cross-site request forgery, we set an '_xsrf' cookie and include the same value as a non-cookie field with all POST requests. If the two do not match, we reject the form submission as a potential forgery. The _xsrf value may be set as either a form field named _xsrf or in a custom HTTP header named X-XSRFToken or X-CSRFToken (the latter is accepted for compatibility with Django). See http://en.wikipedia.org/wiki/Cross-site_request_forgery Prior to release 1.1.1, this check was ignored if the HTTP header "X-Requested-With: XMLHTTPRequest" was present. This exception has been shown to be insecure and has been removed. For more information please see http://www.djangoproject.com/weblog/2011/feb/08/security/ http://weblog.rubyonrails.org/2011/2/8/csrf-protection-bypass-in-ruby-on-rails
def tornado.web.RequestHandler.clear | ( | self | ) |
def tornado.web.RequestHandler.clear_all_cookies | ( | self | ) |
def tornado.web.RequestHandler.clear_cookie | ( | self, | |
name, | |||
path = "/" , |
|||
domain = None |
|||
) |
def tornado.web.RequestHandler.clear_header | ( | self, | |
name | |||
) |
def tornado.web.RequestHandler.compute_etag | ( | self | ) |
def tornado.web.RequestHandler.cookies | ( | self | ) |
def tornado.web.RequestHandler.create_signed_value | ( | self, | |
name, | |||
value | |||
) |
def tornado.web.RequestHandler.create_template_loader | ( | self, | |
template_path | |||
) |
def tornado.web.RequestHandler.current_user | ( | self | ) |
The authenticated user for this request. Determined by either get_current_user, which you can override to set the user based on, e.g., a cookie. If that method is not overridden, this method always returns None. We lazy-load the current user the first time this method is called and cache the result after that.
def tornado.web.RequestHandler.decode_argument | ( | self, | |
value, | |||
name = None |
|||
) |
Decodes an argument from the request. The argument has been percent-decoded and is now a byte string. By default, this method decodes the argument as utf-8 and returns a unicode string, but this may be overridden in subclasses. This method is used as a filter for both get_argument() and for values extracted from the url and passed to get()/post()/etc. The name of the argument is provided if known, but may be None (e.g. for unnamed groups in the url regex).
Reimplemented in tornado.test.web_test.DecodeArgHandler.
def tornado.web.RequestHandler.delete | ( | self, | |
args, | |||
kwargs | |||
) |
def tornado.web.RequestHandler.finish | ( | self, | |
chunk = None |
|||
) |
def tornado.web.RequestHandler.flush | ( | self, | |
include_footers = False , |
|||
callback = None |
|||
) |
Flushes the current output buffer to the network. The ``callback`` argument, if given, can be used for flow control: it will be run when all flushed data has been written to the socket. Note that only one flush callback can be outstanding at a time; if another flush occurs before the previous flush's callback has been run, the previous callback will be discarded.
def tornado.web.RequestHandler.get | ( | self, | |
args, | |||
kwargs | |||
) |
Reimplemented in tornado.web.StaticFileHandler.
def tornado.web.RequestHandler.get_argument | ( | self, | |
name, | |||
default = _ARG_DEFAULT , |
|||
strip = True |
|||
) |
Returns the value of the argument with the given name. If default is not provided, the argument is considered to be required, and we throw an HTTP 400 exception if it is missing. If the argument appears in the url more than once, we return the last value. The returned value is always unicode.
def tornado.web.RequestHandler.get_arguments | ( | self, | |
name, | |||
strip = True |
|||
) |
def tornado.web.RequestHandler.get_browser_locale | ( | self, | |
default = "en_US" |
|||
) |
def tornado.web.RequestHandler.get_cookie | ( | self, | |
name, | |||
default = None |
|||
) |
def tornado.web.RequestHandler.get_current_user | ( | self | ) |
def tornado.web.RequestHandler.get_login_url | ( | self | ) |
Override to customize the login URL based on the request. By default, we use the 'login_url' application setting.
Reimplemented in tornado.test.web_test.AuthRedirectRequestHandler.
def tornado.web.RequestHandler.get_secure_cookie | ( | self, | |
name, | |||
value = None , |
|||
max_age_days = 31 |
|||
) |
def tornado.web.RequestHandler.get_status | ( | self | ) |
def tornado.web.RequestHandler.get_template_path | ( | self | ) |
def tornado.web.RequestHandler.get_user_locale | ( | self | ) |
def tornado.web.RequestHandler.head | ( | self, | |
args, | |||
kwargs | |||
) |
def tornado.web.RequestHandler.initialize | ( | self | ) |
Hook for subclass initialization. A dictionary passed as the third argument of a url spec will be supplied as keyword arguments to initialize(). Example:: class ProfileHandler(RequestHandler): def initialize(self, database): self.database = database def get(self, username): ... app = Application([ (r'/user/(.*)', ProfileHandler, dict(database=database)), ])
def tornado.web.RequestHandler.locale | ( | self | ) |
def tornado.web.RequestHandler.on_connection_close | ( | self | ) |
Called in async handlers if the client closed the connection. Override this to clean up resources associated with long-lived connections. Note that this method is called only if the connection was closed during asynchronous processing; if you need to do cleanup after every request override `on_finish` instead. Proxies may keep a connection open for a time (perhaps indefinitely) after the client has gone away, so this method may not be called promptly after the end user closes their connection.
Reimplemented in tornado.websocket.WebSocketHandler, and tornado.test.web_test.ConnectionCloseHandler.
def tornado.web.RequestHandler.on_finish | ( | self | ) |
def tornado.web.RequestHandler.options | ( | self, | |
args, | |||
kwargs | |||
) |
def tornado.web.RequestHandler.patch | ( | self, | |
args, | |||
kwargs | |||
) |
def tornado.web.RequestHandler.post | ( | self, | |
args, | |||
kwargs | |||
) |
def tornado.web.RequestHandler.prepare | ( | self | ) |
Called at the beginning of a request before `get`/`post`/etc. Override this method to perform common initialization regardless of the request method.
Reimplemented in tornado.web.FallbackHandler, tornado.web.ErrorHandler, and tornado.test.web_test.TypeCheckHandler.
def tornado.web.RequestHandler.put | ( | self, | |
args, | |||
kwargs | |||
) |
def tornado.web.RequestHandler.redirect | ( | self, | |
url, | |||
permanent = False , |
|||
status = None |
|||
) |
Sends a redirect to the given (optionally relative) URL. If the ``status`` argument is specified, that value is used as the HTTP status code; otherwise either 301 (permanent) or 302 (temporary) is chosen based on the ``permanent`` argument. The default is 302 (temporary).
def tornado.web.RequestHandler.render | ( | self, | |
template_name, | |||
kwargs | |||
) |
def tornado.web.RequestHandler.render_string | ( | self, | |
template_name, | |||
kwargs | |||
) |
def tornado.web.RequestHandler.require_setting | ( | self, | |
name, | |||
feature = "this feature" |
|||
) |
def tornado.web.RequestHandler.reverse_url | ( | self, | |
name, | |||
args | |||
) |
def tornado.web.RequestHandler.send_error | ( | self, | |
status_code = 500 , |
|||
kwargs | |||
) |
Sends the given HTTP error code to the browser. If `flush()` has already been called, it is not possible to send an error, so this method will simply terminate the response. If output has been written but not yet flushed, it will be discarded and replaced with the error page. Override `write_error()` to customize the error page that is returned. Additional keyword arguments are passed through to `write_error`.
def tornado.web.RequestHandler.set_cookie | ( | self, | |
name, | |||
value, | |||
domain = None , |
|||
expires = None , |
|||
path = "/" , |
|||
expires_days = None , |
|||
kwargs | |||
) |
def tornado.web.RequestHandler.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.
def tornado.web.RequestHandler.set_header | ( | self, | |
name, | |||
value | |||
) |
def tornado.web.RequestHandler.set_secure_cookie | ( | self, | |
name, | |||
value, | |||
expires_days = 30 , |
|||
kwargs | |||
) |
Signs and timestamps a cookie so it cannot be forged. You must specify the ``cookie_secret`` setting in your Application to use this method. It should be a long, random sequence of bytes to be used as the HMAC secret for the signature. To read a cookie set with this method, use `get_secure_cookie()`. Note that the ``expires_days`` parameter sets the lifetime of the cookie in the browser, but is independent of the ``max_age_days`` parameter to `get_secure_cookie`. Secure cookies may contain arbitrary byte values, not just unicode strings (unlike regular cookies)
def tornado.web.RequestHandler.set_status | ( | self, | |
status_code | |||
) |
def tornado.web.RequestHandler.settings | ( | self | ) |
def tornado.web.RequestHandler.static_url | ( | self, | |
path, | |||
include_host = None |
|||
) |
Returns a static URL for the given relative static file path. This method requires you set the 'static_path' setting in your application (which specifies the root directory of your static files). We append ?v=<signature> to the returned URL, which makes our static file handler set an infinite expiration header on the returned content. The signature is based on the content of the file. By default this method returns URLs relative to the current host, but if ``include_host`` is true the URL returned will be absolute. If this handler has an ``include_host`` attribute, that value will be used as the default for all `static_url` calls that do not pass ``include_host`` as a keyword argument.
def tornado.web.RequestHandler.write | ( | self, | |
chunk | |||
) |
Writes the given chunk to the output buffer. To write the output to the network, use the flush() method below. If the given chunk is a dictionary, we write it as JSON and set the Content-Type of the response to be application/json. (if you want to send JSON as a different Content-Type, call set_header *after* calling write()). Note that lists are not converted to JSON because of a potential cross-site security vulnerability. All JSON output should be wrapped in a dictionary. More details at http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx
def tornado.web.RequestHandler.write_error | ( | self, | |
status_code, | |||
kwargs | |||
) |
Override to implement custom error pages. ``write_error`` may call `write`, `render`, `set_header`, etc to produce output as usual. If this error was caused by an uncaught exception, an ``exc_info`` triple will be available as ``kwargs["exc_info"]``. Note that this exception may not be the "current" exception for purposes of methods like ``sys.exc_info()`` or ``traceback.format_exc``. For historical reasons, if a method ``get_error_html`` exists, it will be used instead of the default ``write_error`` implementation. ``get_error_html`` returned a string instead of producing output normally, and had different semantics for exception handling. Users of ``get_error_html`` are encouraged to convert their code to override ``write_error`` instead.
def tornado.web.RequestHandler.xsrf_form_html | ( | self | ) |
An HTML <input/> element to be included with all POST forms. It defines the _xsrf input value, which we check on all POST requests to prevent cross-site request forgery. If you have set the 'xsrf_cookies' application setting, you must include this HTML within all of your HTML forms. See check_xsrf_cookie() above for more information.
def tornado.web.RequestHandler.xsrf_token | ( | self | ) |
The XSRF-prevention token for the current user/session. To prevent cross-site request forgery, we set an '_xsrf' cookie and include the same '_xsrf' value as an argument with all POST requests. If the two do not match, we reject the form submission as a potential forgery. See http://en.wikipedia.org/wiki/Cross-site_request_forgery
list tornado::web.RequestHandler::_ARG_DEFAULT = [] [static, private] |
tornado::web.RequestHandler::_finished [private] |
Reimplemented in tornado.web.FallbackHandler.
tornado::web.RequestHandler::_headers [private] |
tornado::web.RequestHandler::_locale [private] |
tornado::web.RequestHandler::_new_cookie [private] |
tuple tornado::web.RequestHandler::_template_loader_lock = threading.Lock() [static, private] |
dictionary tornado::web.RequestHandler::_template_loaders = {} [static, private] |
tornado::web.RequestHandler::_transforms [private] |
tornado::web.RequestHandler::_xsrf_token [private] |
Reimplemented in tornado.test.web_test.CookieTestRequestHandler.
tuple tornado::web.RequestHandler::SUPPORTED_METHODS [static] |