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.
Ben Darnell [Sun, 12 May 2013 23:34:12 +0000 (19:34 -0400)]
Allow prepare to be asynchronous, and detect coroutines by their result.
The prepare method does not use the @asynchronous decorator, only
@gen.coroutine (or @return_future; it detects the Future return type).
The same logic is now available for the regular http verb methods as well.
bind_unused_port was passing 0 as port number to the socket module.
This generated some exceptional behaviour on systems where nslookup of
localhost didn't returned the loopback interface.
Ben Darnell [Sun, 5 May 2013 16:58:34 +0000 (12:58 -0400)]
Create UIModule proxies on demand instead of in RequestHandler init.
It would be nice to do something similar for UI methods, but it's tricker
and they are less common (there are three UIModules defined by default
for every handler).
Ben Darnell [Sun, 5 May 2013 14:45:36 +0000 (10:45 -0400)]
Rewrite HTTPHeaders normalization to limit the growth of the cache.
Reorganize the code into a dict subclass for speed: cache hits are now
just a dict lookup, with no python function call. (this saves about 1%
on demos/benchmark/benchmark.py on cpython 2.7)
Remove the regex-based fast path, which has not had any real impact since
we added the dict cache.
Ben Darnell [Mon, 29 Apr 2013 03:25:23 +0000 (23:25 -0400)]
Fix a memory leak in HTTPServer with very large file uploads.
This is not quite a true leak since the garbage collector will
reclaim everything when it runs, but it might as well be a leak
because CPython's garbage collector uses heuristics based on the
number of allocated objects to decide when to run. Since this
scenario resulted in a small number of very large objects, the process
could consume a large amount of memory.
The actual change is to ensure that HTTPConnection always sets a
close_callback on the IOStream instead of waiting for the Application
to set one. I also nulled out a few more references to break up cycles.