Commit Graph

173 Commits

Author SHA1 Message Date
Weihang Lo
c71abe5c20 docs(client): doc tests to async/await 2019-07-15 11:21:16 -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
01c03db7ea chore(lib): add dyn keyword to trait objects (#1820)
Requires Rust 1.27.
2019-06-03 13:08:13 -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
Kevin Leimkuhler
7dcd4618c0 feat(http2): Add window size config options for Client and Server
Add `fn http2_initial_stream_window_size` and `fn
http2_initial_connection_window_size` for client and server.

Closes #1771
2019-03-01 14:44:38 -08:00
Sean McArthur
3a6080b14a fix(client): coerce HTTP_2 requests to HTTP_11
Closes #1770
2019-02-27 17:00:25 -08:00
Sean McArthur
c0e08a41cc refactor(lib): improve client and h1 logs 2019-02-15 15:58:35 -08:00
Sean McArthur
d16b2c3081 fix(client): fix panic when CONNECT request doesn't have a port 2019-02-11 12:05:52 -08:00
Sean McArthur
18f022c70b docs(lib): fix several broken links throughout docs
Closes #1749
Closes #1750
2019-01-24 11:20:22 -08:00
Alexander Mielczarek
078ed82dd5 feat(client): add conn::Builder::max_buf_size()
This allows users to configure a limit to client connections' read and
write buffers.

Closes #1748
2019-01-24 10:59:24 -08:00
Sean McArthur
8842da9184 docs(client): touch ups for Client, Builder, and connect types 2019-01-10 12:18:16 -08:00
Sean McArthur
f8f926c14c doc(client): document that http2_only needs Prior Knowledge or ALPN
configured.

Closes #1698
2018-12-11 15:41:01 -08:00
Sean McArthur
4b3747110a refactor(client): clean up client config fields 2018-12-05 12:17:03 -08:00
Jeff Labonte
69368f433f refactor(client): update from deprecated Uri::port to port_part (#1722) 2018-11-26 10:06:40 -08:00
Rick Richardson
2e7250b669 feat(client): add http1_read_buf_exact_size Builder option
This changes the read buffer strategy from being adaptive to always
using an exact size for the buffer.
2018-11-21 14:07:21 -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
13d53e1d0c feat(client): adds HttpInfo to responses when HttpConnector is used
- Adds `client::connect::Connected::extra()`, which allows connectors to
  specify arbitrary custom information about a connected transport.

If a connector provides this extra value, it will be set in the
`Response` extensions.

Closes #1402
2018-10-16 14:40:50 -07:00
Sean McArthur
efd2c281b8 refactor(client): add comments about the checkout vs connect race 2018-09-28 12:50:45 -07:00
Sean McArthur
b0c132023c refactor(client): change retryable request future from boxed to 'impl Future' 2018-09-28 12:01:37 -07:00
Sean McArthur
bddc2d5040 refactor(client): clarify some code in send_request 2018-09-28 10:24:19 -07:00
Sean McArthur
af23dda2e9 refactor(client): breakout checkout and connect race into separate function 2018-09-28 10:24:19 -07:00
Sean McArthur
5e159a58b4 refactor(client): breakout connect_to future into separate function 2018-09-28 10:24:19 -07:00
Sean McArthur
5bfc110538 refactor(client): improve connect module structure 2018-09-27 14:50:11 -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
6e8417e08f refactor(lib): use type macro to detect impl Trait 2018-08-07 21:00:02 -07:00
Niv Kaminer
9f8add6056 chore(client): place the use of new rust features behind cfg 2018-08-07 19:36:00 -07:00
Niv Kaminer
4290b8bba4 perf(client): replace usage of Box<Trait> with impl Trait 2018-08-07 19:36:00 -07:00
Jonas Platte
51223efb8a docs(lib): Fix some typos 2018-07-08 10:10:12 -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
2a3844acc3 feat(client): enable CONNECT requests through the Client
While the upgrades feature enabled HTTP upgrades in both and the server and client, and the goal was for `CONNECT` requests to work as well, only the server could use them for `CONNECT`. The `Client` had some specific code rejecting `CONNECT` requests, and this removes it and prepares the `Client` to handle them correctly.
2018-06-22 21:00:28 -07:00
Sean McArthur
61f31b5a4a doc(client): show spawning a client future, clarify lazy in client example 2018-06-18 17:02:57 -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
fea29b29e2 feat(http1): Add higher-level HTTP upgrade support to Client and Server (#1563)
- Adds `Body::on_upgrade()` that returns an `OnUpgrade` future.
- Adds `hyper::upgrade` module containing types for dealing with
  upgrades.
- Adds `server::conn::Connection::with_upgrades()` method to enable
  these upgrades when using lower-level API (because of a missing
  `Send` bound on the transport generic).
- Client connections are automatically enabled.
- Optimizes request parsing, to make up for extra work to look for
  upgrade requests.
  - Returns a smaller `DecodedLength` type instead of the fatter
    `Decoder`, which should also allow a couple fewer branches.
  - Removes the `Decode::Ignore` wrapper enum, and instead ignoring
    1xx responses is handled directly in the response parsing code.

Ref #1563 

Closes #1395
2018-06-14 13:39:29 -07:00
Sean McArthur
19f90242f8 feat(body): remove Body::is_empty()
BREAKING CHANGE: `Body::is_empty()` is gone. Replace with
  `Body::is_end_stream()`, from the `Payload` trait.
2018-05-30 13:22:37 -07:00
Sean McArthur
26417fc24a perf(h1): improve parsing and encoding of http1 messages 2018-05-15 13:24:58 -07:00
Sean McArthur
04c74ef596 feat(client): rename FutureResponse to ResponseFuture
BREAKING CHANGE: Replace any references of
  `hyper::client::FutureResponse` to `hyper::client::ResponseFuture`.
2018-05-04 15:21:59 -07:00
Sean McArthur
190a8501d6 docs(client): add module level docs for hyper::client 2018-05-02 13:32:46 -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
11c92ff467 chore(tests): set a short timeout on the integration clients pool 2018-04-26 12:37:31 -07:00
Sean McArthur
d19d95af77 refactor(client): pass internal executor to h2 dispatcher 2018-04-25 17:55:45 -07:00
Matt Bilker
a02fec8c78 feat(client): add support for title case header names (#1497)
This introduces support for the HTTP/1 Client to write header names as title case when encoding
the request.

Closes #1492
2018-04-24 16:41:02 -07:00
Sean McArthur
6906ced872 fix(client): handle race condition when sending while connection is closing 2018-04-24 13:58:10 -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
2dc6202fe7 feat(service): introduce hyper-specific Service
This introduces the `hyper::service` module, which replaces
`tokio-service`.

Since the trait is specific to hyper, its associated
types have been adjusted. It didn't make sense to need to define
`Service<Request=http::Request>`, since we already know the context is
HTTP. Instead, the request and response bodies are associated types now,
and slightly stricter bounds have been placed on `Error`.

The helpers `service_fn` and `service_fn_ok` should be sufficient for
now to ease creating `Service`s.

The `NewService` trait now allows service creation to also be
asynchronous.

These traits are similar to `tower` in nature, and possibly will be
replaced completely by it in the future. For now, hyper defining its own
allows the traits to have better context, and prevents breaking changes
in `tower` from affecting hyper.

Closes #1461

BREAKING CHANGE: The `Service` trait has changed: it has some changed
  associated types, and `call` is now bound to `&mut self`.

  The `NewService` trait has changed: it has some changed associated
  types, and `new_service` now returns a `Future`.

  `Client` no longer implements `Service` for now.

  `hyper::server::conn::Serve` now returns `Connecting` instead of
  `Connection`s, since `new_service` can now return a `Future`. The
  `Connecting` is a future wrapping the new service future, returning
  a `Connection` afterwards. In many cases, `Future::flatten` can be
  used.
2018-04-17 17:09:15 -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
dfdca25c00 feat(body): rename Entity to Payload
Closes #1464
2018-04-10 15:55:23 -07:00