Commit Graph

152 Commits

Author SHA1 Message Date
Vivek Ghaisas
35825c4614 style(comments): correct some typos in Rust code comments 2019-12-20 10:16:36 -08:00
Sean McArthur
4b6099c7aa feat(body): implement HttpBody for Request and Response
When the body type of a `Request` or `Response` implements `HttpBody`,
the `Request` or `Response` itself now implements `HttpBody`.

This allows writing things like `hyper::body::aggregate(req)` instead of
`hyper::body::aggregate(req.into_body())`.

Closes #2067
2019-12-13 10:48:30 -08:00
Euclidr
bfda390617 docs(server): http_proxy example 2019-12-12 16:59:38 -08:00
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
5a59875742 feat(body): replace Chunk type with Bytes
Closes #1931

BREAKING CHANGE: All usage of `hyper::Chunk` should be replaced with
  `bytes::Bytes` (or `hyper::body::Bytes`).
2019-12-05 17:22:13 -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
4d7a2266b8 feat(client): change connectors to return an impl Connection
Instead of returning a tuple `(impl AsyncRead + AsyncWrite, Connected)`,
this adds a new trait, `hyper::client::connect::Connection`, which
allows querying the connection type for a `Connected`.

BREAKING CHANGE: Connectors no longer return a tuple of
  `(T, Connected)`, but a single `T: Connection`.
2019-12-04 16:15:28 -08:00
Sean McArthur
6ae5889f83 feat(rt): introduce rt::Executor trait
The `hyper::rt::Executor` trait allows defining custom executors to be
used with hyper's `Client` and `Server`.

Closes #1944

BREAKING CHANGE: Any type passed to the `executor` builder methods must
  now implement `hyper::rt::Executor`.

  `hyper::rt::spawn` usage should be replaced with `tokio::task::spawn`.

  `hyper::rt::run` usage should be replaced with `#[tokio::main]` or
  managing a `tokio::runtime::Runtime` manually.
2019-12-04 11:38:23 -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
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