Commit Graph

23 Commits

Author SHA1 Message Date
Sean McArthur
2d2d5574a6 feat(lib): redesign API to use Futures and Tokio
There are many changes involved with this, but let's just talk about
user-facing changes.

- Creating a `Client` and `Server` now needs a Tokio `Core` event loop
to attach to.
- `Request` and `Response` both no longer implement the
`std::io::{Read,Write}` traits, but instead represent their bodies as a
`futures::Stream` of items, where each item is a `Chunk`.
- The `Client.request` method now takes a `Request`, instead of being
used as a builder, and returns a `Future` that resolves to `Response`.
- The `Handler` trait for servers is no more, and instead the Tokio
`Service` trait is used. This allows interoperability with generic
middleware.

BREAKING CHANGE: A big sweeping set of breaking changes.
2017-01-16 10:44:27 -08:00
Shane Gibbs
3f34f2bd1d fix(http): move hup check before writable check 2016-11-18 16:03:58 +00:00
Shane Gibbs
359493f973 fix(http): move hup check after read/write check 2016-11-17 18:14:01 -08:00
Joe Wilm
20fac49aa9 fix(http): Prevent busy looping
We encountered some issues where the `Conn::ready()` would busy loop on
reads. Previously, the `ConnInner::can_read_more()` would not consider
whether the previous read got a WouldBlock error, and it didn't consider
whether the transport was blocked. Accounting for this additional state
fixes the busy loop problem.
2016-10-13 14:38:36 -07:00
Joe Wilm
915af2a3a8 fix(http): Handle readable in keep-alive
It's possible that a connection will be closed and the only way to find
out is by doing a read. The keep-alive state (State::Init + Next_::Wait)
now tries to read on readable. In the case of EOF, it returns state
closed. If bytes are actually available, it's a connection error, and
the connection is closed. Otherwise, it's just a spurious wakeup.
2016-10-13 14:38:26 -07:00
Joe Wilm
9652a42d45 fix(conn): Handle remote hangup
Not handling this was an issue for keep-alive connections because
requests would get assigned to a closed connection and then immediately
error. Handling the HUP event makes this situation much less likely. It
is still possible however; consider the situation where a HUP arrives
while the event loop is busy processing new requests to add. The
connection is disconnected, but the HUP hasn't been processed, and a
request could be assigned to it. This case is, however, unlikely.
2016-10-10 15:44:51 -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
15d9da5eb9 fix(client): keep-alive works as intended now
We observed an issue where connection were not ever entering the
keep-alive state due to a bug with `State::update`. The issue is
resolved with resetting the write state to KeepAlive when it arrives as
KeepAlive. Otherwise, it would be marked incorrectly as Closed.

The `trace!` lines in here are useful for debugging keep-alive issues so
I've left them in.
2016-10-06 14:04:01 -07:00
Sean McArthur
a3a815c09c perf(http): reduce server loops when headers and body are ready 2016-08-06 00:11:45 -07:00
Sean McArthur
523b890a19 fix(server): support HTTP/1.1 pipelining 2016-08-06 00:10:46 -07:00
Sean McArthur
81e7bf4155 refactor(http): call on_error for more error cases 2016-07-29 14:25:12 -07:00
leonardo.yvens
211b408b92 style(http): Rustfmt State.update 2016-07-27 10:46:04 -03:00
leonardo.yvens
9f249bbee8 refactor(http): Dedup code in connection state update. 2016-07-27 10:45:57 -03:00
leonardo.yvens
c6eea3761b refactor(http): Remove new_state and use nested match for http1 in connection state update. 2016-07-27 10:45:51 -03: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
Sean McArthur
c856de0428 feat(client): add method to end a chunked body for a Request
Closes #831
2016-06-17 07:01:42 -07:00
Tom Burdick
13a6a59d9d perf(http): reduce memcpy calls using boxed pimpl
All of the move semantics remain the same for http::Conn while
the self consumption and move semantics only require a pointer copy
now rather than copying larger amounts of data. This greatly improves
the performance of hyper, by my measurements about 125% faster when
benchmarking using wrk.
2016-06-14 11:28:09 -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
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