Commit Graph

91 Commits

Author SHA1 Message Date
Sean McArthur
da9b0319ef refactor(lib): update to 2018 edition 2019-07-09 15:16:01 -07:00
Sean McArthur
8b45af7f31 feat(server): add initial window builder methods that take self by-val (#1817)
The current `Builder` methods `http2_initial_stream_window_size` and
`http2_initial_connection_window_size` take `&mut self`, while every
other builder method takes `self`. That breaks up the chaining of
options.

This patch adds two methods that configure the same option, but take
`self` instead, and have an underscore suffix (so,
`http2_initial_stream_window_size_`).

cc #1814
2019-05-16 14:34:28 -07:00
Sean McArthur
973f981aa5 chore(benches): add a few parallel + body end-to-end configurations 2019-05-16 13:34:13 -07:00
Sean McArthur
fd25129dc0 perf(http1): implement an adaptive read buffer strategy
The default read strategy for HTTP/1 connections is now adaptive. It
increases or decreases the size of the read buffer depending on the
number of bytes that are received in a `read` call. If a transport
continuously fills the read buffer, it will continue to grow (up to the
`max_buf_size`), allowing for reading faster. If the transport
consistently only fills a portion of the read buffer, it will be shrunk.

This doesn't provide much benefit to small requests/responses, but
benchmarks show it to be a noticeable improvement to throughput when
streaming larger bodies.

Closes #1708
2018-11-28 12:54:17 -08:00
Sean McArthur
576addd531 test(benches): don't concat chunks, just drop them 2018-10-25 17:22:01 -07:00
Sean McArthur
79f970c7ff test(benches): clean up end_to_end benchmark configuration 2018-10-25 17:15:06 -07:00
Sean McArthur
b20971cb4e perf(http2): less eager server polls since it hurts parallel flushing 2018-10-24 15:35:11 -07:00
Sean McArthur
94e02ac276 perf(http2): eagerly poll some futures in h2 dispatchers before allocating in executor 2018-10-24 15:04:30 -07:00
Sean McArthur
dcf0347151 test(benches): add http1 pipeline bench target 2018-10-23 16:01:16 -07:00
Sean McArthur
4843364b5a test(benches): uses current_thread runtime in server benchmarks 2018-10-23 15:38:06 -07:00
Sean McArthur
e4ebf44823 chore(tests): change tests to use current_thread runtime 2018-06-18 12:30:56 -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
c4974500ab feat(server): re-design Server as higher-level API
The `hyper::Server` is now a proper higher-level API for running HTTP
servers. There is a related `hyper::server::Builder` type, to construct
a `Server`. All other types (`Http`, `Serve`, etc) were moved into the
"lower-level" `hyper::server::conn` module.

The `Server` is a `Future` representing a listening HTTP server. Options
needed to build one are set on the `Builder`.

As `Server` is just a `Future`, it no longer owns a thread-blocking
executor, and can thus be run next to other servers, clients, or
what-have-you.

Closes #1322
Closes #1263

BREAKING CHANGE: The `Server` is no longer created from `Http::bind`,
  nor is it `run`. It is a `Future` that must be polled by an
  `Executor`.

  The `hyper::server::Http` type has move to
  `hyper::server::conn::Http`.
2018-04-16 14:29:19 -07:00
Sean McArthur
dfdca25c00 feat(body): rename Entity to Payload
Closes #1464
2018-04-10 15:55:23 -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
c210524e94 chore(tests): fix tokio runtime deprecations 2018-04-10 12:56:55 -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
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
3cd48b45fb feat(lib): replace types with those from http crate
BREAKING CHANGE: `Method`, `Request`, `Response`, `StatusCode`,
  `Version`, and `Uri` have been replaced with types from the `http`
  crate. The `hyper::header` module is gone for now.

  Removed `Client::get`, since it needed to construct a `Request<B>`
  with an empty body. Just use `Client::request` instead.

  Removed `compat` cargo feature, and `compat` related API.
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
68377ede70 perf(http): utilize writev when possible
By using `AsyncWrite::write_buf`, we can avoid some copies in some
cases. This especially helps throughput for chunked encoding.
2018-01-25 14:02:11 -08:00
Sean McArthur
5c170e8ccd test(server): improve server throughput benchmarks 2018-01-24 11:38:00 -08:00
Sean McArthur
4de0de73be test(benches): fix deprecated futures usage in benches 2018-01-23 16:34:16 -08:00
Sean McArthur
50fd4ab96d chore(benches): remove unused pretty_env_logger import 2017-08-28 15:11:52 -07:00
Yazad Daruvala
b914d2f1ea test(server): add benches for TransferEncoding::chunked 2017-06-17 22:41:10 -07:00
Sean McArthur
900ce1c36f test(server): add benchmark of hyper server vs raw tcp 2017-05-12 16:04:47 -07:00
Sean McArthur
4fb7e6ebc6 feat(lib): remove extern Url type usage
BREAKING CHANGE: The `Url` type is no longer used. Any instance in the
  `Client` API has had it replaced with `hyper::Uri`.

  This also means `Error::Uri` has changed types to
  `hyper::error::UriError`.

  The type `hyper::header::parsing::HTTP_VALUE` has been made private,
  as an implementation detail. The function `http_percent_encoding`
  should be used instead.
2017-03-21 11:03:57 -07:00
Sean McArthur
dc97dd77f4 feat(server): make Http default its body type to hyper::Chunk 2017-02-22 16:30:20 -08:00
Sean McArthur
1b1311a7d3 feat(http): allow specifying custom body streams 2017-02-16 15:06:55 -08:00
Alex Crichton
f45e9c8e4f refactor(server): expose Http that implements ServerProto
The main changes are:

* The entry point is how `Http`, the implementation of `ServerProto`.
  This type has a `new` constructor as well as builder methods to
  configure it.

* A high-level entry point of `Http::bind` was added which returns a
  `Server`. Binding a protocol to a port requires a socket address
  (where to bind) as well as the instance of `NewService`. Internally
  this creates a core and a TCP listener.

* The returned `Server` has a few methods to learn about itself, e.g.
  `local_addr` and `handle`, but mainly has two methods: `run` and
  `run_until`.

* The `Server::run` entry point will execute a server infinitely, never
  having it exit.

* The `Server::run_until` method is intended as a graceful shutdown
  mechanism. When the provided future resolves the server stops
  accepting connections immediately and then waits for a fixed period of
  time for all active connections to get torn down, after which the
  whole server is torn down anyway.

* Finally a `Http::bind_connection` method exists as a low-level entry
  point to spawning a server connection. This is used by `Server::run`
  as is intended for external use in other event loops if necessary or
  otherwise low-level needs.

BREAKING CHANGE: `Server` is no longer the pimary entry point. Instead,
  an `Http` type is created  and then either `bind` to receiver a `Server`,
  or it can be passed to other Tokio things.
2017-01-18 14:09:20 -08:00
Sean McArthur
be461b4663 perf(http): introduce MemBuf, a shared read buffer 2017-01-16 10:50:35 -08:00
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
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
23f20c7576 test(bench): switch vec_push_all to extend_from_slice
Closes #702
2015-12-14 13:46:43 -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
d2e9c94cf5 chore(nightly): remove ()'s and fix benchmarks for nightly
Also ensure that `cargo bench` runs successfully on travis; the old
`cargo bench ... || :` has the effect of ignoring any errors in it.
2015-10-14 15:04:15 +11:00
Sebastian Thiel
eb38a11b9a fix(benches): adjust to missing set_ssl_verifier
In 53bba6e , ssl usage was improved. The existing benchmark
implementation wasn't adjusted though.

This commit fixes the client benchmark to work with the latest nightly
rust and instructs travis to try compile the benchmarks
when rustc nightly is used. This should prevent such kind of breakage
in future.
2015-06-26 14:06:47 +02:00
Pyfisch
195a89fa91 refactor(headers): errors for parse_header
Header::parse_header() returns now a hyper Result instead of an option
this will enable more precise Error messages in the future, currently
most failures are reported as ::Error::Header.

BREAKING CHANGE: parse_header returns Result instead of Option, related
code did also change
2015-06-10 22:22:56 +02: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
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
Sean McArthur
26478644b4 test(benches): remove unused server bench 2015-03-23 11:14:11 -07:00
Sean McArthur
5d7be77e4a feat(server): use SocketAddrs instead of Ipv4Addrs 2015-03-20 17:32:51 -07:00
Sebastian Thiel
104d49036f fix(benches): removed unused features
* 'io' and 'net'
2015-03-20 10:43:18 +01:00
Adrian Heine
1f0bc951c9 fix(rustup): adapt to current rustc
Closes #381.
2015-03-19 09:44:40 +01:00
Sean McArthur
4fd8a6a9dc fix(rustup): update to latest rustc 2015-03-16 12:01:38 -07:00
Sean McArthur
df756871ed feat(headers): adds re-parsing ability when getting typed headers
BREAKING CHANGE: added requirement that all HeaderFormat implementations
  must also be fmt::Debug. This likely as easy as slapping
  #[derive(Debug)] on to any custom headers.
2015-03-03 18:51:29 -08:00
Sean McArthur
0fd6fcd7c7 feat(hyper): switch to std::io, std::net, and std::path.
All instances of `old_io` and `old_path` were switched to use the new
shiny `std::io`, `std::net`, and `std::path` modules. This means that
`Request` and `Response` implement `Read` and `Write` now.

Because of the changes to `TcpListener`, this also takes the opportunity
to correct the method usage of `Server`. As with other
languages/frameworks, the server is first created with a handler, and
then a host/port is passed to a `listen` method. This reverses what
`Server` used to do.

Closes #347

BREAKING CHANGE: Check the docs. Everything was touched.
2015-03-03 14:32:03 -08:00
Renato Zannon
b47f936525 fix(rustup): update feature flags 2015-02-21 15:05:50 -08:00