What’s new in Tornado 2.1¶
Sep 20, 2011¶
Backwards-incompatible changes¶
- Support for secure cookies written by pre-1.0 releases of Tornado has
been removed. The
RequestHandler.get_secure_cookiemethod no longer takes aninclude_nameparameter. - The
debugapplication setting now causes stack traces to be displayed in the browser on uncaught exceptions. Since this may leak sensitive information, debug mode is not recommended for public-facing servers.
Security fixes¶
- Diginotar has been removed from the default CA certificates file used
by
SimpleAsyncHTTPClient.
New modules¶
tornado.gen: A generator-based interface to simplify writing asynchronous functions.tornado.netutil: Parts oftornado.httpserverhave been extracted into a new module for use with non-HTTP protocols.tornado.platform.twisted: A bridge between the Tornado IOLoop and the Twisted Reactor, allowing code written for Twisted to be run on Tornado.tornado.process: Multi-process mode has been improved, and can now restart crashed child processes. A new entry point has been added attornado.process.fork_processes, althoughtornado.httpserver.HTTPServer.startis still supported.
tornado.web¶
tornado.web.RequestHandler.write_errorreplacesget_error_htmlas the preferred way to generate custom error pages (get_error_htmlis still supported, but deprecated)- In
tornado.web.Application, handlers may be specified by (fully-qualified) name instead of importing and passing the class object itself. - It is now possible to use a custom subclass of
StaticFileHandlerwith thestatic_handler_classapplication setting, and this subclass can override the behavior of thestatic_urlmethod. StaticFileHandlersubclasses can now overrideget_cache_timeto customize cache control behavior.tornado.web.RequestHandler.get_secure_cookienow has amax_age_daysparameter to allow applications to override the default one-month expiration.set_cookienow accepts amax_agekeyword argument to set themax-agecookie attribute (note underscore vs dash)tornado.web.RequestHandler.set_default_headersmay be overridden to set headers in a way that does not get reset during error handling.RequestHandler.add_headercan now be used to set a header that can appear multiple times in the response.RequestHandler.flushcan now take a callback for flow control.- The
application/jsoncontent type can now be gzipped. - The cookie-signing functions are now accessible as static functions
tornado.web.create_signed_valueandtornado.web.decode_signed_value.
tornado.httpserver¶
- To facilitate some advanced multi-process scenarios,
HTTPServerhas a new methodadd_sockets, and socket-opening code is available separately astornado.netutil.bind_sockets. - The
cookiesproperty is now available ontornado.httpserver.HTTPRequest(it is also available in its old location as a property ofRequestHandler) tornado.httpserver.HTTPServer.bindnow takes a backlog argument with the same meaning assocket.listen.HTTPServercan now be run on a unix socket as well as TCP.- Fixed exception at startup when
socket.AI_ADDRCONFIGis not available, as on Windows XP
IOLoop and IOStream¶
IOStreamperformance has been improved, especially for small synchronous requests.- New methods
tornado.iostream.IOStream.read_until_closeandtornado.iostream.IOStream.read_until_regex. IOStream.read_bytesandIOStream.read_until_closenow take astreaming_callbackargument to return data as it is received rather than all at once.IOLoop.add_timeoutnow acceptsdatetime.timedeltaobjects in addition to absolute timestamps.PeriodicCallbacknow sticks to the specified period instead of creeping later due to accumulated errors.tornado.ioloop.IOLoopandtornado.httpclient.HTTPClientnow haveclose()methods that should be used in applications that create and destroy many of these objects.IOLoop.installcan now be used to use a custom subclass of IOLoop as the singleton without monkey-patching.IOStreamshould now always call the close callback instead of the connect callback on a connection error.- The
IOStreamclose callback will no longer be called while there are pending read callbacks that can be satisfied with buffered data.
tornado.simple_httpclient¶
- Now supports client SSL certificates with the
client_keyandclient_certparameters totornado.httpclient.HTTPRequest - Now takes a maximum buffer size, to allow reading files larger than 100MB
- Now works with HTTP 1.0 servers that don’t send a Content-Length header
- The
allow_nonstandard_methodsflag on HTTP client requests now permits methods other thanPOSTandPUTto contain bodies. - Fixed file descriptor leaks and multiple callback invocations in
SimpleAsyncHTTPClient - No longer consumes extra connection resources when following redirects.
- Now works with buggy web servers that separate headers with
\ninstead of\r\n\r\n. - Now sets
response.request_timecorrectly. - Connect timeouts now work correctly.
Other modules¶
tornado.auth.OpenIdMixinnow uses the correct realm when the callback URI is on a different domain.tornado.autoreloadhas a new command-line interface which can be used to wrap any script. This replaces the--autoreloadargument totornado.testing.mainand is more robust against syntax errors.tornado.autoreload.watchcan be used to watch files other than the sources of imported modules.tornado.database.Connectionhas new variants ofexecuteandexecutemanythat return the number of rows affected instead of the last inserted row id.tornado.locale.load_translationsnow accepts any properly-formatted locale name, not just those in the predefinedLOCALE_NAMESlist.tornado.options.definenow takes agroupparameter to group options in--helpoutput.- Template loaders now take a
namespaceconstructor argument to add entries to the template namespace. tornado.websocketnow supports the latest (“hybi-10”) version of the protocol (the old version, “hixie-76” is still supported; the correct version is detected automatically).tornado.websocketnow works on Python 3
Bug fixes¶
- Windows support has been improved. Windows is still not an officially
supported platform, but the test suite now passes and
tornado.autoreloadworks. - Uploading files whose names contain special characters will now work.
- Cookie values containing special characters are now properly quoted and unquoted.
- Multi-line headers are now supported.
- Repeated Content-Length headers (which may be added by certain proxies)
are now supported in
HTTPServer. - Unicode string literals now work in template expressions.
- The template
{% module %}directive now works even if applications use a template variable namedmodules. - Requests with “Expect: 100-continue” now work on python 3