Replace `_CRLF_RE.split(headers)` with a simple `headers.split('\n')` with an additional check for `'\r'` in each line.
Add benchmark to measure performance impact of the change.
The benchmark results are as follows:
* split only: ~3x faster on CPython, 14-18x faster on PyPy
* full headers parse: ~1.3x faster on CPython, ~3-4.5x faster on PyPy
Ben Darnell [Sat, 23 Mar 2019 15:11:18 +0000 (11:11 -0400)]
httpclient: HTTPResponse.body returns empty string instead of raising
In tornado 5, HTTPResponse.body would return None if there was no body
buffer (which included errors like timeouts and socket errors, but not
HTTP errors like 404). In tornado 6 this was changed to never return
None (to make it easier to work with type annotations) and raise an
error instead. This turned out to be disruptive, so change it back to
returning a value without raising (but now it's an empty byte string
instead of None).
Pierce Lopez [Fri, 1 Mar 2019 20:22:14 +0000 (15:22 -0500)]
travis-ci tests: always use dist xenial
Travis-CI Trusty Container-based environment was available
between July, 2017 and December, 2018.
https://docs.travis-ci.com/user/reference/overview/#deprecated-virtualization-environments
Ben Darnell [Fri, 1 Mar 2019 20:03:31 +0000 (15:03 -0500)]
Fix importability on python 3.5.2
The "provisional" typing module in 3.5.2 is kind of broken/incomplete
so we need to use more forward references to avoid confusing it. The
significance of this version in particular is that it was the one
included in ubuntu 16.04.
Ben Darnell [Sun, 3 Feb 2019 23:01:53 +0000 (18:01 -0500)]
ioloop: Micro-optimize IOLoop.add_future
Asyncio Futures always schedule their callbacks on a future iteration
of the IOLoop, so routing the callbacks through IOLoop.add_callback
again was redundant and causing unnecessary delays in callback
execution.
Ben Darnell [Tue, 1 Jan 2019 17:50:07 +0000 (12:50 -0500)]
http1connection: Fix a bug with redirects and chunked requests
After a redirect, the chunked-encoding header is already set and would
not be detected correctly. This affects empty bodies with
allow_nonstandard_methods and any use of body_producer.
Ben Darnell [Sun, 30 Dec 2018 17:10:20 +0000 (12:10 -0500)]
websocket: Change some Future type annotations to Awaitables
This conforms with usage elsewhere, that methods returning None use
Futures (self-starting in case the result is not awaited) and others
use Awaitable (reserving the option to use more efficient native
coroutines).
Ben Darnell [Sun, 30 Dec 2018 00:57:39 +0000 (19:57 -0500)]
docs: Use python 3.7 via conda for readthedocs builds
The typing module in python 3.5 has problems with some type
annotations so we need to build with 3.7. RTD doesn't yet support py37
natively but we can get it with conda following an example at
https://github.com/rtfd/readthedocs-docker-images/pull/73
Ben Darnell [Mon, 24 Dec 2018 16:57:33 +0000 (11:57 -0500)]
websocket: Make WSH.get a coroutine
This is necessary to convert accept_connection to native coroutines -
the handshake no longer completes within a single IOLoop iteration
with this change due to coroutine scheduling.
This has the side effect of keeping the HTTP1Connection open for the
lifetime of the websocket connection. That's not great for memory, but
might help streamline close handling. Either way, it'll be refactored
in a future change.
Ben Darnell [Mon, 10 Dec 2018 03:16:33 +0000 (22:16 -0500)]
testing: Cancel all pending coroutines in tearDown
It's difficult to synchronize test shutdown with the exits of all
coroutines, so explicitly cancel all native coroutines (which are
spammy when allowed to be GC'd).
garenchan [Mon, 10 Dec 2018 11:16:38 +0000 (19:16 +0800)]
Use 'future_add_done_callback' to add callback.
The PR #2449 was incomplete, it omited consideration of another
branch of the 'flush' method. In short, the future returned by
'RequestHandler.finish()' may also be the return value of
'HTTP1Connection.write()'. So we should make the same change to
'HTTP1Connection.write()'.
Ben Darnell [Mon, 10 Dec 2018 02:14:50 +0000 (21:14 -0500)]
websocket_test: Remove most manual closes
At one time this was necessary to prevent spurious warnings at
shutdown, but not any more (and I intend to address warnings like this
with a more general solution).
Ben Darnell [Sun, 2 Dec 2018 17:33:07 +0000 (12:33 -0500)]
httpclient: Fix warning logged by sync HTTPClient destructor
If an HTTPClient is closed from its destructor instead of an explicit
close() call, it sometimes logs an "inconsistent AsyncHTTPClient
cache" error because the weakrefs appear to get cleaned up in an
unexpected order. Relax the checks in AsyncHTTPClient.close to allow
for a missing value in the instance cache.
Tornado's limited support for cancellation means that errors after a
Future is cancelled could get raised (and probably logged) as
InvalidStateErrors.
This new function effectively changes the behavior to log the real
exception instead of the InvalidStateError. We log them instead of
ignoring them because it's generally not a good idea to let errors
pass silently even if they're after the point that no one is listening
for them (this is consistent with the way gen.multi() handles multiple
errors, for example).