Ben Darnell [Mon, 9 Aug 2010 21:33:32 +0000 (14:33 -0700)]
Be less picky about line endings in headers in httpclient.
HTTP requires that lines end with \r\n, but some buggy servers (including
news.ycombinator.com) just use \n. Libcurl tolerates this and sends the
line as-is to the header callback, so we need to be prepared to handle
either form.
Ben Darnell [Mon, 9 Aug 2010 21:01:48 +0000 (14:01 -0700)]
The periodic call to multi_socket_all needs to be followed by
_finish_pending_request or else those requests won't be finished until
after the next one is started.
Ben Darnell [Thu, 5 Aug 2010 00:30:20 +0000 (17:30 -0700)]
Add a brute-force workaround for the class of libcurl bugs that cause
file descriptors or timeouts to get silently dropped. (the old
fdset/perform implementation of AsycnHTTPClient had a similar workaround).
Ben Darnell [Fri, 30 Jul 2010 02:08:30 +0000 (19:08 -0700)]
Fix a StackContext-related bug that was causing exceptions in callbacks
to result in timeouts instead of making wait() re-throw the exception.
Add a test to verify that this works.
Ben Darnell [Mon, 26 Jul 2010 19:04:00 +0000 (12:04 -0700)]
Add an initialize() method to RequestHandler for use by subclasses.
This is simpler than overriding __init__ since it doesn't require
knowledge of the application and request arguments that must be
passed through to the superclass's __init__.
Ben Darnell [Fri, 23 Jul 2010 19:35:08 +0000 (12:35 -0700)]
Introduce StackContext, a way to automatically manage exception
handling and other stack-related state for asynchronous callbacks.
This means that it is no longer necessary to wrap everything
in RequestHandler.async_callback.
Ben Darnell [Thu, 22 Jul 2010 21:29:07 +0000 (14:29 -0700)]
Remove websocket.py. The websocket protocol has changed in
incompatible ways (and is still not yet final), so the version
implemented in this module is not compatible with current
browsers. This module may be reintroduced in the future when
we have an implementation of the new protocol.
Ben Darnell [Tue, 20 Jul 2010 02:39:42 +0000 (19:39 -0700)]
When no json library is found, don't throw an exception unless
json functionality is used, to make the simplejson dependency optional
for python 2.5 users.
Ben Darnell [Wed, 14 Jul 2010 23:31:22 +0000 (16:31 -0700)]
Better timeout handling in AsyncHTTPClient2. Tornado and libcurl may
use different clock functions, which can cause timeouts to be delayed
(in some cases until the next fetch is started). This change
resynchronizes the schedule after each timeout call.
Ben Darnell [Sat, 10 Jul 2010 01:15:12 +0000 (18:15 -0700)]
In AsyncHTTPClient2, disable IPv6 for versions of libcurl with the
socket-reopening bug (i.e. <= 7.21.0). (this can be overridden if needed
with a prepare_curl_callback)
Ben Darnell [Fri, 9 Jul 2010 20:07:43 +0000 (13:07 -0700)]
Unquote percent escapes in captured groups in the path component of the URI,
to be more consistent with our handling of query parameters.
This change is slightly backwards-incompatible: applications that have
already added an unquote() call on arguments to RequestHandler.get/post
will need to remove them.
URI spec requires that '/' and '%2F' be distinguishable, so it's incorrect
to escape at this level. The next commit will instead unquote captured
groups before passing them to get()/post() in web.py
Ben Darnell [Fri, 9 Jul 2010 01:27:43 +0000 (18:27 -0700)]
Parse percent escapes in the path component of the uri, to be more
consistent with our handling of query parameters (especially important
when capturing groups are used in the URLSpec regex).
This change is slightly backwards-incompatible: applications that have
already added an unquote() call on arguments to RequestHandler.get/post
or use percent escapes in URLSpec patterns will need to remove them.
Ben Darnell [Sat, 26 Jun 2010 23:00:26 +0000 (16:00 -0700)]
Update the set of active file descriptors immediately after calling perform
instead of after running user callbacks, since those callbacks might have
started using file descriptors that were closed by curl in perform().
Ben Darnell [Fri, 18 Jun 2010 22:59:19 +0000 (15:59 -0700)]
Close wsgi responses correctly - the close method, if present, will
be on the result of self.wsgi_application() and not on the list
of output we're building up.
Ben Darnell [Thu, 10 Jun 2010 21:49:57 +0000 (14:49 -0700)]
In the libcurl file descriptor limit hack, log to both stderr and
logging.error since they may got to different places and one may be
more visible than the other.
Ben Darnell [Mon, 31 May 2010 06:04:10 +0000 (23:04 -0700)]
Optionally allow nonstandard http methods to be used in httpclient.
By default we check that the method is one of the standard ones (and
is capitalized correctly), but this can be overridden to work with a
server that has implemented nonstandard methods (e.g. CouchDB)
Ben Darnell [Mon, 31 May 2010 05:50:11 +0000 (22:50 -0700)]
Clear the close_callback set on the IOStream by RequestHandlers in
finish(), so that the close_callback does not prevent garbage collection
of the handlers.
Ben Darnell [Mon, 31 May 2010 05:16:11 +0000 (22:16 -0700)]
Improve parsing of multipart/form-data headers.
This change was motivated by google app engine's xmpp support,
which uses different spacing in the header than other common clients
and quotes its boundary string.
The one-shot behavior of receive_message was intentional, and simply
requeuing the old callback every time will eventually overflow the
stack due to repeated async_callback wrappers. An alternate interface
that doesn't require receive_message to be called for every message
may be added in a future change.
Ben Darnell [Mon, 17 May 2010 02:33:59 +0000 (19:33 -0700)]
Use a lambda instead of functools.partial for pycurl.HEADERFUNCTION.
Older versions of pycurl (including 7.16.2.1, which is the recommended
version for Mac OS X 10.5) only work with real functions, not objects
with a __call__ method like functools.partial.
Remove exception-swallowing - curl versions that predate HEADERFUNCTION
are no longer supported.
Ben Darnell [Wed, 21 Apr 2010 20:57:05 +0000 (13:57 -0700)]
cStringIO's constructor uses a 16-bit encoding when given a unicode
string. This is inconsistent with its write method, which encodes all
strings as ascii (and rejects unicode strings iff they have any
non-ascii characters). This change uses utf-8 as the default encoding
when constructing cStringIO objects in tornado.
Ben Darnell [Tue, 20 Apr 2010 22:40:33 +0000 (15:40 -0700)]
Send all logging to the root logger instead of per-module loggers.
This undoes the effect of
http://github.com/facebook/tornado/commit/e391fd289ed085671344504cc5b1fa84f5a3c774
Per-module loggers are problematic because only the top-level convenience
logging.{error,warning,...} functions configure logging on-demand, so
an app that only uses per-module loggers will produce no output except
"no handlers found for logger X". Since tornado.ioloop swallows and logs
all exceptions, this makes it too hard to tell what's going on for apps
that do not configure logging explicitly.
Instead of setting log levels on individual module's loggers,
logging.Handler.addFilter can be used with a filter that examines
the module attribute of the log record.
Ben Darnell [Mon, 19 Apr 2010 18:20:03 +0000 (11:20 -0700)]
Better HTTP header parsing: Allow (and strip) any amount of leading
and trailing whitespace around header values instead of just a single
space. Such whitespace is legal but appears to be uncommon (and nginx
apparently normalizes everything to a single space)
http://tools.ietf.org/html/rfc2616#page-31
Ben Darnell [Mon, 5 Apr 2010 19:23:24 +0000 (12:23 -0700)]
Make options.__getattr__ raise AttributeError instead of Error for consistency
with standard attribute lookups (so getattr(options, 'foo', None) works
if no option 'foo' has been defined).