Ben Darnell [Thu, 6 Jun 2013 01:43:16 +0000 (21:43 -0400)]
Catch StreamClosedErrors in WebSocketHandler and abort.
When the stream is closed with buffered data, the close callback won't
be run until all buffered data is consumed, but any attempt to write
to the stream will fail, as will reading past the end of the buffer.
This requires a try/except around each read or write, analogous to the
one introduced in HTTPServer in commit 3258726f.
Ben Darnell [Sat, 1 Jun 2013 21:30:33 +0000 (17:30 -0400)]
Reuse a single ThreadPoolExecutor for all ThreadedResolvers.
The primary motivation is that shutting down a ThreadPoolExecutor takes
100ms in the 2.x backported version of concurrent.futures. It's also
generally unnecessary to create lots of DNS resolver threads just
because multiple resolver objects are used.
Ben Darnell [Sat, 1 Jun 2013 00:45:42 +0000 (20:45 -0400)]
Make the auth*_redirect methods all return Futures.
The OAuth 1.0 authorize_redirect is asynchronous, but this is not obvious
since it doesn't take a callback and instead just calls self.finish.
This fails in coroutines because the request will be auto-finished too soon.
Add Future returns to this method, and to all the rest for consistency.
Update docs and add tests for the various styles of login handlers.
Ben Darnell [Sat, 1 Jun 2013 00:03:02 +0000 (20:03 -0400)]
Doc patch for 3.0: replace @gen.coroutine with @gen.engine.
The oauth 1.0 redirect methods are asynchronous even though they don't
take a callback, so we don't want the end of the coroutine to trigger
a call to self.finish.
Ben Darnell [Sat, 25 May 2013 19:26:37 +0000 (15:26 -0400)]
Use remove and add instead of update_handler in curl_httpclient.
Curl sometimes fails to tell us that it has closed a socket
and reopened a new one with the same file descriptor, leading
to problems in some IOLoops. This should fix the recurring problem
of update_handler errors in various less-common use cases.
Ben Darnell [Fri, 24 May 2013 04:41:23 +0000 (00:41 -0400)]
Revert change to use time.strftime (from 3.0).
time.strftime is influenced by the user's locale (if one is set with
locale.setlocale), so it's not what we want. Go back to the (slower)
email.utils functions.
Ben Darnell [Fri, 24 May 2013 03:57:30 +0000 (23:57 -0400)]
Backport changes from ssl.match_hostname in Python 3.3.
Includes two commits:
* Fix potential CPU DoS via abusive wildcard pattern
http://hg.python.org/cpython/rev/fafd33db6ff6
* Fall back to common name when SAN doesn't contain any DNS names
http://hg.python.org/cpython/rev/1b37827984ba
Ben Darnell [Sun, 19 May 2013 18:23:17 +0000 (14:23 -0400)]
Read static files in 64-KB chunks.
Based on #526, but updated for the new interfaces in StaticFileHandler.
Unlike #526, this change does not actually wait for each chunk to be
flushed before reading the next one. Flushing raises some additional
complications (wsgi compatibility, chunked encoding vs content-length)
that are probably not worthwhile for the intended use of StaticFileHandler.
Reading in chunks has benefits even if we don't wait for the flush
(i.e. memory fragmentation), and this change establishes the necessary
subclass interfaces so we can add flushing in the future.
Ben Darnell [Sun, 19 May 2013 16:41:12 +0000 (12:41 -0400)]
Add method StaticFileHandler.get_content_version.
This method is easier for subclasses to override (the base class still
handles caching) and lets us use the post-validation absolute path,
fixing some issues with default_filename support.
Ben Darnell [Fri, 17 May 2013 04:07:25 +0000 (00:07 -0400)]
Dereference the current YieldPoint as soon as it resolves.
These references could otherwise keep a chain of old references alive
(test code: https://groups.google.com/group/python-tornado/browse_thread/thread/37d3928817e4924d)
Ben Darnell [Mon, 13 May 2013 04:08:04 +0000 (00:08 -0400)]
Remove whitespace/control-character check from RequestHandler.redirect.
Control characters (and newlines and tabs) will be caught in
set_header (which will raise an exception instead of silently
stripping them). Spaces will now be allowed through, producing
invalid urls, but at least they won't mess up the header framing.