Commit Graph

110 Commits

Author SHA1 Message Date
Sean McArthur
8ba9a8d2c4 feat(body): add body::aggregate and body::to_bytes functions
Adds utility functions to `hyper::body` to help asynchronously
collecting all the buffers of some `HttpBody` into one.

- `aggregate` will collect all into an `impl Buf` without copying the
  contents. This is ideal if you don't need a contiguous buffer.
- `to_bytes` will copy all the data into a single contiguous `Bytes`
  buffer.
2019-12-06 10:03:05 -08:00
Sean McArthur
0dc89680cd style(lib): run rustfmt and enforce in CI 2019-12-05 13:55:17 -08:00
Sean McArthur
a738d03fd3 chore(dependencies): update to http-body 0.3 2019-12-04 16:48:06 -08:00
Sean McArthur
319e8aee15 feat(client): remove Destination for http::Uri in connectors
BREAKING CHANGE: All usage of `hyper::client::connect::Destination`
  should be replaced with `http::Uri`.
2019-12-04 16:15:28 -08:00
Sean McArthur
cb3f39c2dc feat(lib): update Tokio, bytes, http, h2, and http-body 2019-12-04 10:56:34 -08:00
Sean McArthur
8b878a805a perf(client): change HttpConnecting to hold Arc<Config> instead of inlined fields 2019-10-23 16:21:51 -07:00
Sean McArthur
5cb95bdda4 test(benches): add http2 chunks benchmark with default window size 2019-10-15 18:29:33 -07:00
Sean McArthur
51cdbea826 test(benches): add end-to-end chunked benchmarks 2019-10-15 18:05:57 -07:00
Sean McArthur
22695968d2 perf(http2): improve default HTTP2 flow control settings
Set default HTTP2 window sizes much larger values than the spec default.

ref #1960
2019-10-08 15:39:35 -07:00
Sean McArthur
049b5132db feat(client): change GaiResolver to use a global blocking threadpool
BREAKING CHANGE: Calls to `GaiResolver::new` and `HttpConnector::new` no
  longer should pass an integer argument for the number of threads.
2019-08-29 14:16:43 -07:00
lzutao
ae75b3a732 chore(lib): remove async_await feature gate (#1909)
`async_await` is stabilized in rust-lang/rust#63209.
2019-08-21 11:09:14 -07:00
Sean McArthur
a22dabd093 fix(server): change Builder window size methods to be by-value
Closes #1814
2019-08-20 17:45:01 -07:00
Sean McArthur
41f4173615 refactor(http2): re-enable http2 client and server support 2019-08-19 15:55:49 -07:00
Weihang Lo
74195bc17b test(end_to_end): ignore unimplemented h2 benchmarks
Signed-off-by: Weihang Lo <me@weihanglo.tw>
2019-07-23 10:53:03 -07:00
Weihang Lo
4f2abd81e8 test(benches): update end to end benchmark to async/await
Signed-off-by: Weihang Lo <me@weihanglo.tw>
2019-07-23 10:53:03 -07:00
Weihang Lo
fb880c6295 test(benches): uncomment deny warning attr 2019-07-23 10:53:03 -07:00
Weihang Lo
db86e554d5 test(benches): update server benchmark to async/await 2019-07-17 10:57:51 -07:00
Weihang Lo
63a8f26583 test(benches): update pipeline benchmark to async/await 2019-07-17 10:57:51 -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
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