Commit Graph

142 Commits

Author SHA1 Message Date
Sean McArthur
4f2743991c feat(service): rename Service to HttpService, re-export tower::Service`
The only important trait for a user is the `tower::Service` trait, which
is now available also at `hyper::service::Service`. The other "trait
aliases" are no longer publicly exported, as people thought they had to
implement them.

Also removes dependency on `tower-make`, which is trivial but otherwise
shouldn't affect anyone.

Closes #1959
2019-10-21 11:01:28 -07:00
memoryruins
1341cde365 refactor(examples): remove lifetime workaround in send_file example
The lifetime workaround is no longer required due to changes in
rustc. This removes the line and comment from the example.
2019-09-11 09:22:48 -07:00
Sean McArthur
0331219b40 docs(examples): add more comments to hello server example 2019-08-30 14:38:22 -07:00
Lucio Franco
eee2a72879 feat(client): provide tower::Service support for clients (#1915) 2019-08-30 12:54:22 -07:00
lzutao
fc7f81b67c style(lib): use rust 2018 edition idioms (#1910) 2019-08-21 11:22:07 -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
Lucio Franco
ec520d5602 feat(service): use tower_service::Service for hyper::service 2019-08-20 12:01:06 -07:00
Yotam Ofek
9d5299b655 refactor(server): work around deprecation of poll_accept method in tokio (#1890) 2019-08-14 11:46:49 -07:00
Daiki Mizukami
0d3cbe28fc refactor(rt): remove re-export of tokio::main (#1879)
Closes #1878.

BREAKING CHANGE: Replace all usage of `rt::main` with `tokio::main`.
2019-07-22 10:06:36 -07:00
Weihang Lo
9ae1873756 docs(examples): formatting and refactoring 2019-07-16 10:08:22 -07:00
Weihang Lo
da187b54e8 docs(examples): move web_api to examples folder 2019-07-16 10:08:22 -07:00
Weihang Lo
e8c19fea4c docs(examples): update send_file example to async/await 2019-07-16 10:08:22 -07:00
Weihang Lo
7cdfd3d974 docs(examples): update upgrade example to async/await 2019-07-15 11:35:33 -07:00
Weihang Lo
39471d7e5e docs(examples): update single_threaded example to async/await 2019-07-15 11:35:33 -07:00
Weihang Lo
22bd31c68f docs(examples): update state example to async/await 2019-07-15 11:35:33 -07:00
Weihang Lo
af78fd3672 docs(examples): update proxy example to async/await 2019-07-15 11:35:33 -07:00
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