176 Commits

Author SHA1 Message Date
Sean McArthur
5da17df97f chore(lib): individually disable tests and examples that aren't updated 2019-07-12 13:44:03 -07:00
messense
f93463b3d9 docs(examples): Update params example to use async await 2019-07-12 10:57:27 -07:00
messense
19ba891fac docs(examples): Update multi_server example to use async await 2019-07-12 10:43:39 -07:00
Fuyang Liu
7ff8fccced docs(examples): update echo example to use async/await 2019-07-12 10:39:08 -07:00
messense
22142943f4 docs(examples): Update client_json example to use async await 2019-07-11 23:17:06 -07:00
Sean McArthur
0bda9ab8c2 docs(examples): update client example to use rt::main 2019-07-10 16:11:05 -07:00
Sean McArthur
f0478c6267 feat(rt): export hyper::rt::main attribute macro
Usage:

    #[hyper::rt::main]
    async fn main() {
        // async stuff in here
    }
2019-07-10 14:12:21 -07:00
Fuyang Liu
67c4781734 docs(examples): Update the example hello (#1852) 2019-07-10 09:43:56 -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
01c03db7ea chore(lib): add dyn keyword to trait objects (#1820)
Requires Rust 1.27.
2019-06-03 13:08:13 -07:00
Ole Herman Schumacher Elgesem
b3deb0cbed docs(server): show JSON deserialization in API example (#1791)
The previous version only showed a JSON GET API.
Deserializing the body of a POST request is not
trivial so the example should show it.

The new example takes the JSON body sent in a
POST request, deserializes it, adds a field, then
serializes it and sends it back.

Signed-off-by: Ole Herman Schumacher Elgesem <oleherman93@gmail.com>
2019-04-09 14:05:16 -07:00
Sean McArthur
30870029b9 feat(server): change NewService to MakeService with connection context
This adjusts the way `Service`s are created for a `hyper::Server`. The
`MakeService` trait allows receiving an argument when creating a
`Service`. The implementation for `hyper::Server` expects to pass a
reference to the accepted transport (so, `&Incoming::Item`). The user
can inspect the transport before making a `Service`.

In practice, this allows for things like getting the remote socket
address, or the TLS certification, or similar.

To prevent a breaking change, there is a blanket implementation of
`MakeService` for any `NewService`. Besides implementing `MakeService`
directly, there is also added `hyper::service::make_service_fn`.

Closes #1650
2018-11-16 13:18:09 -08: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
ced949cb6b feat(server): allow !Send Servers
Until this commit, servers have required that `Service` and their
`Future` to be `Send`, since the server needs to spawn some internal
tasks to an executor, and by default, that is `tokio::spawn`, which
could be spawning to a threadpool. This was true even if the user were
certain there was no threadpool involved, and was instead using a
different single-threaded runtime, like
`tokio::runtime::current_thread`.

This changes makes all the server pieces generic over an `E`, which is
essentially `Executor<PrivateTypes<Server::Future>>`. There's a new set
of internal traits, `H2Exec` and `NewSvcExec`, which allow for the type
signature to only show the generics that the user is providing. The
traits cannot be implemented explicitly, but there are blanket
implementations for `E: Executor<SpecificType>`. If the user provides
their own executor, it simply needs to have a generic `impl<F>
Executor<F> for MyExec`. That impl can have bounds deciding whether to
require `F: Send`. If the executor does require `Send`, and the
`Service` futures are `!Send`, there will be compiler errors.

To prevent a breaking change, all the types that gained the `E` generic
have a default type set, which is the original `tokio::spawn` executor.
2018-10-16 13:21:45 -07:00
Ahmed Charles
9fa721df9e docs(examples): add proxy example 2018-10-02 10:07:31 -07:00
Alexis Mousset
e3dc6c5511 docs(examples): Fix typo in client_json example comment
Fixes typo on comment about error types in client_json example.
2018-08-27 10:23:16 -07:00
Sean McArthur
ae34a86cc3 docs(examples): add a stateful server example with a request counter 2018-07-06 15:24:01 -07:00
Özgür Akkurt
bff37244d8 docs(server): clean the web_api example up
add comments and a json example

closes #1595
2018-07-06 12:37:50 -07:00
Özgür Akkurt
9cd971d8f3 docs(client): improve client_json example 2018-07-06 12:37:50 -07:00
ozgurakkurt
e06dc52ef6 docs(client): Add client_json example
Closes #1581
2018-07-03 14:41:50 -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
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
1e3bc6bf1a chore(examples): fix echo compilation without NLL 2018-06-05 12:33:14 -07:00
Sean McArthur
41291346d0 docs(examples): add comments to the echo example 2018-06-05 12:27:33 -07:00
Josh Leeb-du Toit
924c6da25b docs(examples): update echo example with functionality from the guide
Update the echo example based on the functionality explained in the
Hyper guide: https://hyper.rs/guides/server/echo

Closes #1528
2018-06-05 11:38:59 -07:00
Aaron Riekenberg
7eca445ff9 docs(examples): Update send_file example to use tokio-fs 2018-06-04 09:59:42 -07:00
meven
2415ce96e1 docs(examples): add README for examples directory
Closes #1511
2018-05-30 00:39:05 +02:00
Ran Benita
f98f168f07 fix(examples): remove unused imports from examples/client.rs 2018-05-04 13:22:31 +03:00
Sean McArthur
a16234fa26 docs(examples): add some comments in the client example 2018-05-03 12:00:44 -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
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
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
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
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
fbc449e49c feat(body): introduce an Entity trait to represent bodies
This dedicated `Entity` trait replaces the previous `Stream<Item=impl
AsRef<[u8]>, Error=hyper::Error>`. This allows for several improvements
immediately, and prepares for HTTP2 support.

- The `Entity::is_end_stream` makes up for change away from
  `Option<Body>`, which was previously used to know if the body should be
  empty. Since `Request` and `Response` now require a body to be set,
  this method can be used to tell hyper that the body is actually empty.

  It also provides the possibility of slight optimizations when polling
  for data, by allowing to check `is_end_stream` before polling again.
  This can allow a consumer to know that a body stream has ended without
  polling for `None` afterwards.

- The `Entity::content_length` method allows a body to automatically
  declare a size, in case a user doesn't set a `Content-Length` or
  `Transfer-Encoding` header.

- It's now possible to send and receive trailers, though this will be
  for HTTP2 connections only.

By being a trait owned by hyper, new methods can be added later as new
features are wanted (with default implementations).

The `hyper::Body` type now implements `Entity` instead of `Stream`,
provides a better channel option, and is easier to use with custom
streams via `Body::wrap_stream`.

BREAKING CHANGE: All code that was assuming the body was a `Stream` must
  be adjusted to use an `Entity` instead.

  Using `hyper::Body` as a `Stream` can call `Body::into_stream`
  to get a stream wrapper.

  Passing a custom `impl Stream` will need to either implement
  `Entity`, or as an easier option, switch to `Body::wrap_stream`.

  `Body::pair` has been replaced with `Body::channel`, which returns a
  `hyper::body::Sender` instead of a `futures::sync::mpsc::Sender`.

Closes #1438
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
Klaus Purer
3a36eb5596 fix(server): Make sleep_on_errors configurable and use it in example 2018-02-24 16:19:01 +01:00
Greedwolf DSS
73511ac8be docs(example): fix send file to only send range of buffer read into 2018-01-16 11:52:56 -08:00
Sean McArthur
34f0dba6dc chore(log): update to log 0.4 2018-01-04 14:50:18 -08:00
Sean McArthur
6ade21aa7f feat(server): change default dispatcher
- Deprecates the `no_proto` configuration on `Server`. It is always
  enabled.
- Deprecates all pieces related to tokio-proto.
- Makes the tokio-proto crate optional, and the `server-proto` feature
  can be used to completely remove the dependency. It is enabled by
  default.
2017-12-28 19:15:57 -08:00
Sean McArthur
0892cb2777 feat(client): replace default dispatcher 2017-12-28 17:18:42 -08:00
Sean McArthur
6fde13f759 Merge pull request #1406 from jolhoeft/web_api
docs(server): Add server example querying a web api
2017-12-28 15:42:35 -08:00
Jeff Olhoeft
7d2cce0922 docs(server): Add an example of serving files 2017-12-27 16:07:20 -08:00
Jeff Olhoeft
ebb5882859 docs(server): Add server example querying a web api 2017-12-27 15:47:46 -08:00
Jeff Olhoeft
61877f6f6e docs(server): Add a forms server example
Add an example program illustrating parsing a request body through
generating a response body.
2017-12-13 14:30:04 -08:00