Commit Graph

69 Commits

Author SHA1 Message Date
Sean McArthur
cb3f39c2dc feat(lib): update Tokio, bytes, http, h2, and http-body 2019-12-04 10:56:34 -08:00
Daniel Johnson
71d088d3d0 chore(dependencies): update futures to 0.3.1 2019-11-14 10:04:16 -08:00
Sean McArthur
e6027bc02d fix(client): fix panic from unreachable code 2019-10-30 13:45:23 -07:00
Sean McArthur
d46cde1216 test(client): remove warning about disabled tests 2019-09-11 14:55:14 -07:00
Weihang Lo
144893b409 Upgrade some lib tests to async/.await version (#1882)
* test(http): use async/.await

Signed-off-by: Weihang Lo <me@weihanglo.tw>

* test(pool): use async/.await

* test(pool): pass &mut Future into PollOnce

* test(client): tests/benches using async/.await

* test(client): change due to PR #1917

* test(client): change Delay to delay fucntion

Ref: https://github.com/tokio-rs/tokio/pull/1440

* test(client): remove warning triggers
2019-09-06 09:54:11 -07:00
lzutao
fc7f81b67c style(lib): use rust 2018 edition idioms (#1910) 2019-08-21 11:22:07 -07:00
Sean McArthur
5da17df97f chore(lib): individually disable tests and examples that aren't updated 2019-07-12 13:44:03 -07:00
Sean McArthur
8f4b05ae78 feat(lib): update to std::future::Future
BREAKING CHANGE: All usage of async traits (`Future`, `Stream`,
`AsyncRead`, `AsyncWrite`, etc) are updated to newer versions.
2019-07-09 15:55:22 -07:00
Sean McArthur
da9b0319ef refactor(lib): update to 2018 edition 2019-07-09 15:16:01 -07:00
Sean McArthur
271bba1667 refactor(error): improve organization of Error kinds
- Placed all cases of "unexpected bytes" errors into the
  `UnexpectedMessage` variant.
- Placed all cases of "unexpected EOF" errors into the
  `IncompleteMessage` variant. Description is now generic about
  "connection closed before message completed", instead of mentioning
  "request" or "response.
- Added `Error::is_incomplete_message()` accessor to help checking for
  unexpected closures.
- Renamed some variants to be clearer when viewing the `Debug` format.
- Collected all "user" errors into an internal `User` enum, to prevent
  forgetting to update the `is_user()` method.
2019-04-26 10:44:40 -07:00
quininer
4133181bb2 fix(client): fix a rare connection pool race condition
It's possible for `PoolInner::put` to happen between `Pool::take` and `Pool::waiter`. This merges `take` and `waiter` into using the same lock.
2019-04-23 13:55:34 -07:00
Sean McArthur
c0e08a41cc refactor(lib): improve client and h1 logs 2019-02-15 15:58:35 -08:00
Sean McArthur
3287a0cdab test(client): fix pool tests compilation errors 2018-12-06 16:55:24 -08:00
Sean McArthur
4b3747110a refactor(client): clean up client config fields 2018-12-05 12:17:03 -08:00
Sean McArthur
976a77a673 feat(client): add ALPN h2 support for client connectors
- Adds `Connected::negotiated_h2()` method to signal the connection must
  use HTTP2. `Connect` implementations should set this if using ALPN.

If a connection to a host is detected to have been upgraded via ALPN,
any other oustanding connect futures will be canceled, and the waiting
requests will make use of the single HTTP2 connection.

The `http2_only` builder configuration still works the same, not
requiring ALPN at all, and always using only a single connection.
2018-10-31 14:51:29 -07:00
Sean McArthur
192348d7ef refactor(client): don't allocate PoolInner if pool is disabled 2018-09-28 11:13:22 -07:00
Sean McArthur
5e159a58b4 refactor(client): breakout connect_to future into separate function 2018-09-28 10:24:19 -07:00
Sean McArthur
a3c44ded55 feat(client): add max_idle_per_host configuration option
Setting this will cap the amount of idle connections kept around for a
specific host. This defaults to no limit (`usize::MAX`).
2018-08-22 12:28:49 -07:00
Sean McArthur
f2d464ac79 fix(client): try to reuse connections when pool checkout wins
If a checkout wins, meaning an idle connection became available before
a connect future completed, instead of just dropping the connect future,
it spawns it into the background executor to allow being placed into
the pool on completion.
2018-06-28 12:43:56 -07:00
Sean McArthur
482a5f589e fix(lib): return an error instead of panic if execute fails
If executing an internal task fails, a new variant of `hyper::Error` is
returned to the user, with improved messaging.

If a non-critical task fails to spawn, it no longer panics, instead just
logging a warning.

Closes #1566
2018-06-18 16:01:04 -07:00
Sean McArthur
e4ebf44823 chore(tests): change tests to use current_thread runtime 2018-06-18 12:30:56 -07:00
Sean McArthur
dfa7e17960 refactor(client): change last Weak::new to an Option<Weak> 2018-05-04 15:36:20 -07:00
Sean McArthur
7a7453ba52 refactor(lib): change from futures-timer to tokio-timer 2018-04-30 19:11:05 -07:00
Sean McArthur
5e3b43af09 fix(client): prevent a checkout loop of pooled connections that aren't ready yet 2018-04-30 14:06:12 -07:00
Sean McArthur
d19d95af77 refactor(client): pass internal executor to h2 dispatcher 2018-04-25 17:55:45 -07:00
Sean McArthur
d127201ef2 feat(rt): make tokio runtime optional
A Cargo feature `runtime` is added, which is enabled by default, that
includes the following:

- The `client::HttpConnector`, which uses `tokio::net::TcpStream`.
- The `server::AddrStream`, which uses `tokio::net::TcpListener`.
- The `hyper::rt` module, which includes useful utilities to work with
  the runtime without needing to import `futures` or `tokio` explicity.

Disabling the feature removes many of these niceties, but allows people
to use hyper in environments that have an alternative runtime, without
needing to download an unused one.
2018-04-23 16:56:26 -07:00
Sean McArthur
1328412f82 refactor(client): skip some pool housekeeping on shared h2 handles 2018-04-18 16:36:52 -07:00
Sean McArthur
c119097fd0 feat(http2): add HTTP/2 support for Client and Server 2018-04-13 14:23:47 -07:00
Sean McArthur
fe1578acf6 feat(client): update construction of Clients
- `Client::new()` no longer needs a `Handle`, and instead makes use of
  tokio's implicit default.
- Changed `Client::configure()` to `Client::builder()`.
- `Builder` is a by-ref builder, since all configuration is now
  cloneable pieces.

BREAKING CHANGE: `Client:new(&handle)` and `Client::configure()` are now
  `Client::new()` and `Client::builder()`.
2018-04-10 17:30:10 -07:00
Sean McArthur
5d3c472228 feat(error): revamp hyper::Error type
**The `Error` is now an opaque struct**, which allows for more variants to
be added freely, and the internal representation to change without being
breaking changes.

For inspecting an `Error`, there are several `is_*` methods to check for
certain classes of errors, such as `Error::is_parse()`. The `cause` can
also be inspected, like before. This likely seems like a downgrade, but
more inspection can be added as needed!

The `Error` now knows about more states, which gives much more context
around when a certain error occurs. This is also expressed in the
description and `fmt` messages.

**Most places where a user would provide an error to hyper can now pass
any error type** (`E: Into<Box<std::error::Error>>`). This error is passed
back in relevant places, and can be useful for logging. This should make
it much clearer about what error a user should provide to hyper: any it
feels is relevant!

Closes #1128
Closes #1130
Closes #1431
Closes #1338

BREAKING CHANGE: `Error` is no longer an enum to pattern match over, or
  to construct. Code will need to be updated accordingly.

  For body streams or `Service`s, inference might be unable to determine
  what error type you mean to return. Starting in Rust 1.26, you could
  just label that as `!` if you never return an error.
2018-04-10 14:29:34 -07:00
Sean McArthur
625e4daaa1 Revert "refactor(lib): convert to futures 0.2.0-beta (#1470)"
This reverts commit a12f7beed9.

Much sadness 😢.
2018-04-10 12:56:55 -07:00
Sean McArthur
c1f84af481 refactor(client): notify idle interval when pool drops 2018-04-02 10:34:34 -07:00
Sam Rijs
a12f7beed9 refactor(lib): convert to futures 0.2.0-beta (#1470) 2018-03-29 13:32:44 -07:00
Sam Reis
27b8db3af8 feat(lib): convert to use tokio 0.1
BREAKING CHANGE: All uses of `Handle` now need to be new-tokio `Handle`.

Co-authored-by: Sean McArthur <sean@seanmonstar.com>
2018-03-19 11:43:47 -07:00
Sean McArthur
1207c2b624 feat(client): introduce lower-level Connection API
Closes #1449
2018-03-07 14:26:52 -08:00
Sean McArthur
4351ed1d13 chore(client): fix unused_mut warning in 1.18 2018-02-28 16:45:43 -08:00
Sean McArthur
2fa0c845b5 fix(client): check conn is closed in expire interval 2018-02-28 15:16:01 -08:00
Sean McArthur
727b74797e fix(client): schedule interval to clear expired idle connections
Currently only works if Client is built with a `Handle`, and not a
custome executor, since a `Handle` is required to create a tokio
Interval.
2018-02-28 14:57:06 -08:00
Sean McArthur
1223fc28ee wip 2018-02-28 13:58:38 -08:00
Sean McArthur
ee61ea9adf feat(client): Client will retry requests on fresh connections
If a request sees an error on a pooled connection before ever writing
any bytes, it will now retry with a new connection.

This can be configured with `Config::retry_canceled_requests(bool)`.
2018-02-15 12:04:58 -08:00
Sean McArthur
b7293ca6ff refactor(client): clean up pool Checkout::poll function 2018-02-05 11:53:17 -08:00
Sean McArthur
44af273853 fix(client): check for dead connections in Pool
Closes #1429
2018-01-29 11:58:05 -08:00
Sean McArthur
7b5931122a feat(log): improve quality of debug level logs 2017-12-08 14:49:51 -08:00
Steven Fackler
d2aa5d862c fix(client): don't leak connections with no keep-alive
Closes #1383
2017-11-27 21:42:57 -08:00
Sean McArthur
b1765dd168 fix(client): drop in-use connections when they finish if Client is dropped 2017-10-30 15:20:56 -07:00
Sean McArthur
0fbc215f4b fix(client): fix panic in Pool
Closes #1339
2017-09-28 21:44:41 -07:00
Sean McArthur
5027435791 refactor(lib): rename internal http module to proto 2017-09-28 18:28:44 -07:00
Sean McArthur
3b91fc65b2 fix(client): cleanup dropped pending Checkouts from Pool
Closes #1315
2017-09-18 13:29:31 -07:00
Sean McArthur
4dfe0db0f4 perf(server): dont record Idle time when not needed 2017-06-25 11:51:43 -07:00
Sean McArthur
c166268c07 fix(client): prevent panicking when determine Expiration in pool
On some OSes, `Instant` would start counting 0 from the boot time. That
would mean that any `Instant::now() - dur` soon after boot had a higher
risk of overflowing. Now, the expiration is determined by calling
`idle.elapsed()`, and comparing durations.

Closes #1215
2017-06-13 09:21:56 -07:00