Commit Graph

217 Commits

Author SHA1 Message Date
Joe Wilm
ff556199e6 fix(client): Improve keep-alive reuse strategy
The previous keep-alive strategy was to cycle connections in a
round-robin style. However, that will always keep more connections
around than are needed. This new strategy will allow extra connections
to expire when only a few are needed. This is accomplished by prefering
to reuse a connection that was just released to the pool over one that
has been there for a long time.
2016-10-13 14:38:31 -07:00
Joe Wilm
34c4d72712 fix(client): Always register for hup 2016-10-13 14:38:19 -07:00
Joe Wilm
ef4c08c9e9 fix(client): Handle connection error
Previously, the connection would be kept alive if there was a connect
error. Now it's closed immediately.
2016-10-13 14:38:10 -07:00
Joe Wilm
934f2c481b fix(http): Connection checks for spurious timeouts
We've been seeing a strange number of timeouts in our benchmarking.
Handling spurious timeouts as in this patch seems to fix it!

Note that managing the `timeout_start` needs to be done carefully. If
the current time is provided in the wrong place, it's possible requests
would never timeout.
2016-10-07 17:59:47 -07:00
Joe Wilm
c32d0e9adf fix(http): stackoverflow in Conn::ready
I've had a couple of instances during stress testing now where
Conn::ready would overflow its stack due to recursing on itself. This
moves subsequent calls to ready() into a loop outside the function.
2016-10-06 18:02:26 -07:00
Joe Wilm
138e1643e8 feat(client): DNS worker count is configurable
When loading up a client suddenly with thousands of connections, the
default DNS worker count of four cannot keep up and many requests
timeout as a result. Most people don't need a large pool, so making this
configurable is a natural choice.
2016-10-06 14:50:30 -07:00
Joe Wilm
27cab3766d fix(client): Evict idle connections when full
In the scenario where a request is started on the `Client`, the client
has a full slab, and sockets for a *different* domain are idling in
keep-alive, the new request would previously cause the client to panic!.

This patch adds a `spawn_error` handler which attempts to evict an idle
connection to make space for the new request. If space cannot be made,
the error handler is run (passed `Error::Full`) and the `Handler` is
dropped.

This is a breaking change because of the new variant of `Error`.

Some inefficient use of `Vec` in the client was replaced with `VecDeque`
to support push/pop from either end.
2016-09-21 17:52:38 -07:00
Ahmed Charles
8b3c120684 feat(server): add path() and query() to Request
Closes #896 
Closes #897

BREAKING CHANGE: `RequestUri::AbsolutePath` variant is changed to a struct variant. Consider using `req.path()` or `req.query()` to get the relevant slice.
2016-08-29 13:45:38 -07:00
Sean McArthur
976218badc feat(client): add keep_alive_timeout to Client 2016-07-14 19:55:55 -07:00
Sean McArthur
006f66f34a fix(client): handle when DNS resolves after a timeout triggers
Closes #848
2016-07-13 14:48:11 -07:00
Sean McArthur
2904668105 feat(client): implement connection pooling for Client
Closes #830
Closes #848
2016-07-08 10:07:02 -07:00
Sean McArthur
2fbd80ce69 feat(server): add Transport to on_request 2016-06-23 15:29:30 -07:00
leonardo.yvens
d4a095d75c refactor(multiple): Clippy run 2016-06-12 15:17:15 -03:00
Sean McArthur
8017dac175 chore(http): reduce some logs from error level 2016-05-29 15:50:04 -07:00
Sean McArthur
2d9aea8db0 fix(client): send query parameters in Requests 2016-05-23 11:19:43 -07:00
Sean McArthur
d35992d019 feat(lib): switch to non-blocking (asynchronous) IO
BREAKING CHANGE: This breaks a lot of the Client and Server APIs.
  Check the documentation for how Handlers can be used for asynchronous
  events.
2016-05-16 09:51:18 -07:00
Sean McArthur
f36c6b255f feat(client): proper proxy and tunneling in Client
Closes #774
2016-05-02 12:33:49 -07:00
Sean McArthur
25010fc1fc feat(client): add Proxy support
This works by configuring proxy options on a `Client`, such as
`client.set_proxy("http", "127.0.0.1", "8018")`.

Closes #531
2016-04-25 15:49:57 -07:00
Simon Sapin
8fa7a98968 refactor(hyper): Update to rust-url 1.0
BREAKING CHANGE: The re-exported Url type has breaking changes.
2016-04-21 16:14:08 -07:00
Steven Fackler
8c7ef7fd93 feat(client): Implement Debug for Client
Protocol doesn't extend Debug so we have to leave that out of the
output unfortunately.
2016-02-15 14:43:50 -08:00
Corey Farwell
4c7f6f0c1e style(all): Address suggestions made by rust-clippy 2015-12-23 08:59:45 -08:00
Sean McArthur
fec6e3e873 feat(all): add socket timeouts
Methods added to `Client` and `Server` to control read and write
timeouts of the underlying socket.

Keep-Alive is re-enabled by default on the server, with a default
timeout of 5 seconds.

BREAKING CHANGE: This adds 2 required methods to the `NetworkStream`
  trait, `set_read_timeout` and `set_write_timeout`. Any local
  implementations will need to add them.
2015-11-24 10:58:58 -08:00
Huon Wilson
ff4a607057 refactor(client): make RequestBuilder non-generic
Improve the compile-time of downstream crates that use RequestBuilder,
by not forcing them to remonomorphise and recompile its non-generic
methods when they use it: with this change, they can just call the
precompiled versions in the `hyper` object file(s). The `send` method is
the major culprit here, since it is quite large and complicated.

For an extreme example,

    extern crate hyper;
    fn main() {
        hyper::Client::new().get("x").send().unwrap();
    }

takes ~4s to compile before this patch (i.e. generic RequestBuilder) and
~2s after. (The time spent interacting with LLVM goes from 2.2s to
0.3s.)

BREAKING CHANGE: `RequestBuilder<U>` should be replaced by `RequestBuilder`.
2015-10-14 15:23:55 +11:00
softprops
03827c3156 feat(client): add patch method to Client builder interface 2015-10-01 22:30:52 -04:00
Sean McArthur
75c7117020 fix(client): be resilient to invalid response bodies
When an Http11Message knows that the previous response should not
have included a body per RFC7230, and fails to parse the following
response, the bytes are shuffled along, checking for the start of the
next response.

Closes #640
2015-09-01 16:58:51 -07:00
Sean McArthur
7d1f154cb7 feat(net): add socket timeouts to Server and Client
While these methods are marked unstable in libstd, this is behind a
feature flag, `timeouts`. The Client and Server both have
`set_read_timeout` and `set_write_timeout` methods, that will affect all
connections with that entity.

BREAKING CHANGE: Any custom implementation of NetworkStream must now
  implement `set_read_timeout` and `set_write_timeout`, so those will
  break. Most users who only use the provided streams should work with
  no changes needed.

Closes #315
2015-07-27 09:57:59 -07:00
Pyfisch
db93ca0697 style(rustfmt): run rustfmt on hyper correct overlong lines 2015-06-29 20:22:22 +02:00
Sean McArthur
53bba6eb7f feat(ssl): redesign SSL usage
BREAKING CHANGE: Server::https was changed to allow any implementation
  of Ssl. Server in general was also changed. HttpConnector no longer
  uses SSL; using HttpsConnector instead.
2015-06-20 14:58:58 -07:00
Sean McArthur
7d2e5c0ef8 style(client): use status.is_redirection() 2015-06-17 11:36:54 -07:00
Sean McArthur
64e47b4bbd feat(client): impl Sync for Client
Connector::connect already used &self, and so would require
synchronization to be handled per connector anyway. Adding Sync to the
Client allows users to setup config for a Client once, such as using a
single connection Pool, and then making requests across multiple
threads.

Closes #254

BREAKING CHANGE: Connectors and Protocols passed to the `Client` must
  now also have a `Sync` bounds, but this shouldn't break default usage.
2015-06-12 11:19:54 -07:00
Sean McArthur
71ac65da5b refactor(http): move h1 and h2 into http module 2015-06-02 12:24:56 -07:00
Marko Lalic
d3e3a45760 refactor(client): use a Protocol to create a message for a Request 2015-06-02 14:34:13 +02:00
Marius Seritan
be041d915a feat(client): implement Default trait for client
Initial implementation of the default trait.
2015-05-15 22:35:42 -07:00
Sean McArthur
7e3858c962 perf(all): replace &str.to_string() with .to_owned() 2015-05-12 23:01:58 -07:00
Sean McArthur
1b318724a5 feat(net): remove mut requirement for NetworkConnector.connect()
BREAKING CHANGE: Any custom Connectors will need to change to &self in
  the connect method. Any Connectors that needed the mutablity need to
  figure out a synchronization strategy.

  Request::with_connector() takes a &NetworkConnector instead of &mut.
  Any uses of with_connector will need to change to passing &C.
2015-05-09 23:14:23 -07:00
Sean McArthur
7bc4e83ec2 Merge pull request #518 from mlalic/fix-client-ssl-verifier
fix(client): keep the underlying connector when setting an SSL verifier
2015-05-09 22:46:43 -07:00
Sean McArthur
a3637d5f73 refactor(all): adjust some logging 2015-05-09 22:18:05 -07:00
Marko Lalic
f4556d554f fix(client): keep the underlying connector when setting an SSL verifier
The client no longer drops the old `Connector` instance, along with its
entire context (such as the settings and pooled connections in the case
of a `Pool` connector); rather, it passes the SSL verifier on to the
`Connector` so that it uses it for any future connections that it needs
to establish.

A regression test is included.

Closes #495
2015-05-09 20:10:51 +02:00
Marko Lalic
a5d632b6ea feat(net): add set_ssl_verifier method to NetworkConnector trait
The commit includes an implementation of the new trait method for all
existing trait impls.

BREAKING CHANGE: Adding a new required method to a public trait is a
breaking change.
2015-05-09 20:10:51 +02:00
Sean McArthur
972b3a388a feat(error): add Ssl variant to hyper::Error
The errors from openssl were previously boxed into a
Box<std::error::Error>, which lost some specifics and made it difficult
to match against. To solve this, an `Ssl` variant is added to the
`Error` enum of hyper, and is returned when openssl returns specific
errors.

Closes #483

BREAKING CHANGE: Adds a variant to `hyper::Error`, which may break any
exhaustive matches.
2015-05-05 18:25:19 -07:00
Tshepang Lekhonkhobe
7ddea2791c docs(misc): fix typos caught by codespell 2015-05-06 02:34:07 +02:00
Sean McArthur
9ba074d150 refactor(error): remove redundant parts of error names
The old names followed the old style of including the module name and
"Error" in each variant. The new style is to refer to an error from its
owning module, and variants are now scoped to their enum, so there's no
need to include the enum name in the variant name.

BREAKING CHANGE: The terms `Http` and `Error` have been removed from the Error
  type and its variants. `HttpError` should now be accessed as `hyper::Error`,
  and variants like `HttpIoError` should be accessed as `Error::Io`.
2015-05-05 11:53:09 -07:00
Sean McArthur
1e72a8ab3a feat(client): add a Connection Pool
This adds a connection pool to the Client that is used by default. It
accepts any other NetworkConnector, and simply acts as a
NetworkConnector itself. Other Pools can exist by simply providing a
custom NetworkConnector. This Pool is only used by default if you also
use the default connector, which is `HttpConnector`. If you wish to use
the Pool with a custom connector, you'll need to create the Pool with
your custom connector, and then pass that pool to the
Client::with_connector.

This also adds a method to `NetworkStream`, `close`, which can be used
to know when the Stream should be put down, because a server requested
that the connection close instead of be kept alive.

Closes #363
Closes #41
2015-04-29 12:58:28 -07:00
Sean McArthur
e814680b55 Merge pull request #473 from hyperium/docup
Docup
2015-04-22 15:45:09 -07:00
Sean McArthur
48a010ffd7 docs(client): add improved usage examples 2015-04-22 12:28:19 -07:00
Sean McArthur
a2aefd9a56 feat(client): accept &String as Body in RequestBuilder
BREAKING CHANGE: This removes the trait `IntoBody`, and instead using
  `Into<Body>`, as it's more idiomatic. This will only have broken code
  that had custom implementations of `IntoBody`, and can be fixed by
  changing them to `Into<Body>`.
2015-04-16 10:25:12 -07:00
Sean McArthur
8bc179fb51 feat(client): accept &String for a Url in RequestBuilder
adds an IntoUrl implementation for &String
2015-04-16 10:10:42 -07:00
Sean McArthur
0fb92ee735 feat(debug): add Debug impls for StatusClass, Server, and Listening 2015-04-16 10:04:51 -07:00
Sean McArthur
4f09b002ff feat(log): clean up logging 2015-04-15 21:08:52 -07:00
Sean McArthur
139a51f1c3 feat(client): remove generic parameter for Connector
Closes #379

BREAKING CHANGE: For people using the default HttpConnector and Client,
    everything should continue to just work. If the Client has been
    used with a generic parameter, it should be removed.

    However, there were some breaking changes to the internals of
    NetworkConnectors. Specifically, they no longer return a
    NetworkStream, but instead a Into<Box<NetworkStream + Send>>. All
    implementations of NetworkStream should continue to just work,
    however.

    Possible breakages could come from the stricter usage of Send
    throughout the Client API.
2015-04-03 18:36:13 -07:00