Skip to content

Commit 6805221

Browse files
oddgrdseanmonstar
authored andcommitted
chore: update hyper crates, use hyper io traits
1 parent 7a09dbc commit 6805221

5 files changed

Lines changed: 38 additions & 13 deletions

File tree

.github/workflows/check_guides.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ EOF
1919
fi
2020
if [ $value = stable ]; then
2121
cat >> "$value/Cargo.toml" <<-EOF
22-
hyper = { version = "1.0.0-rc.3", features = ["full"] }
22+
hyper = { version = "1.0.0-rc.4", features = ["full"] }
2323
tokio = { version = "1", features = ["full"] }
24-
http-body-util = "0.1.0-rc.2"
24+
http-body-util = "0.1.0-rc.3"
25+
hyper-util = { git = "https://github.com/hyperium/hyper-util.git" }
2526
EOF
2627
cargo build --manifest-path "$value/Cargo.toml"
2728
fi

_config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ relative_links:
5353
plugins:
5454
- jekyll-redirect-from
5555

56-
docs_url: https://docs.rs/hyper/1.0.0-rc.3
56+
docs_url: https://docs.rs/hyper/1.0.0-rc.4
5757
examples_url: https://github.com/hyperium/hyper/tree/master/examples
58-
http_body_util_url: https://docs.rs/http-body-util/0.1.0-rc.2
58+
http_body_util_url: https://docs.rs/http-body-util/0.1.0-rc.3
5959
hyper_tls_url: https://docs.rs/hyper-tls/*
6060

6161
futures_url: https://docs.rs/futures/0.3.*

_stable/client/basic.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ Let's tell Cargo about our dependencies by having this in the Cargo.toml.
1111

1212
```toml
1313
[dependencies]
14-
hyper = { version = "1.0.0-rc.3", features = ["full"] }
14+
hyper = { version = "1.0.0-rc.4", features = ["full"] }
1515
tokio = { version = "1", features = ["full"] }
16-
http-body-util = "0.1.0-rc.2"
16+
http-body-util = "0.1.0-rc.3"
17+
hyper-util = { git = "https://github.com/hyperium/hyper-util.git" }
1718
```
1819

1920
Now, we need to import pieces to use from our dependencies:
@@ -22,9 +23,11 @@ Now, we need to import pieces to use from our dependencies:
2223
# extern crate http_body_util;
2324
# extern crate hyper;
2425
# extern crate tokio;
26+
# extern crate hyper_util;
2527
use http_body_util::Empty;
2628
use hyper::Request;
2729
use hyper::body::Bytes;
30+
use hyper_util::rt::TokioIo;
2831
use tokio::net::TcpStream;
2932
# fn main() {}
3033
```
@@ -74,10 +77,12 @@ setup we'll spawn a `tokio::task` and `await` it.
7477
```rust
7578
# extern crate http_body_util;
7679
# extern crate hyper;
80+
# extern crate hyper_util;
7781
# extern crate tokio;
7882
# use http_body_util::Empty;
7983
# use hyper::body::Bytes;
8084
# use hyper::Request;
85+
# use hyper_util::rt::TokioIo;
8186
# use tokio::net::TcpStream;
8287
# async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
8388
// Parse our URL...
@@ -92,8 +97,12 @@ let address = format!("{}:{}", host, port);
9297
// Open a TCP connection to the remote host
9398
let stream = TcpStream::connect(address).await?;
9499

100+
// Use an adapter to access something implementing `tokio::io` traits as if they implement
101+
// `hyper::rt` IO traits.
102+
let io = TokioIo::new(stream);
103+
95104
// Perform a TCP handshake
96-
let (mut sender, conn) = hyper::client::conn::http1::handshake(stream).await?;
105+
let (mut sender, conn) = hyper::client::conn::http1::handshake(io).await?;
97106

98107
// Spawn a task to poll the connection, driving the HTTP state
99108
tokio::task::spawn(async move {
@@ -126,18 +135,21 @@ status of the response to see that it returned the expected `200 OK` status.
126135
```rust
127136
# extern crate http_body_util;
128137
# extern crate hyper;
138+
# extern crate hyper_util;
129139
# extern crate tokio;
130140
# use http_body_util::Empty;
131141
# use hyper::body::Bytes;
132142
# use hyper::Request;
143+
# use hyper_util::rt::TokioIo;
133144
# use tokio::net::TcpStream;
134145
# async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
135146
# let url = "http://httpbin.org/ip".parse::<hyper::Uri>()?;
136147
# let host = url.host().expect("uri has no host");
137148
# let port = url.port_u16().unwrap_or(80);
138149
# let addr = format!("{}:{}", host, port);
139150
# let stream = TcpStream::connect(addr).await?;
140-
# let (mut sender, conn) = hyper::client::conn::http1::handshake(stream).await?;
151+
# let io = TokioIo::new(stream);
152+
# let (mut sender, conn) = hyper::client::conn::http1::handshake(io).await?;
141153
# tokio::task::spawn(async move {
142154
# if let Err(err) = conn.await {
143155
# println!("Connection failed: {:?}", err);
@@ -182,10 +194,12 @@ use tokio::io::{stdout, AsyncWriteExt as _};
182194
```rust
183195
# extern crate http_body_util;
184196
# extern crate hyper;
197+
# extern crate hyper_util;
185198
# extern crate tokio;
186199
# use http_body_util::{BodyExt, Empty};
187200
# use hyper::body::Bytes;
188201
# use hyper::Request;
202+
# use hyper_util::rt::TokioIo;
189203
# use tokio::net::TcpStream;
190204
# use tokio::io::{self, AsyncWriteExt as _};
191205
# async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
@@ -194,7 +208,8 @@ use tokio::io::{stdout, AsyncWriteExt as _};
194208
# let port = url.port_u16().unwrap_or(80);
195209
# let addr = format!("{}:{}", host, port);
196210
# let stream = TcpStream::connect(addr).await?;
197-
# let (mut sender, conn) = hyper::client::conn::http1::handshake(stream).await?;
211+
# let io = TokioIo::new(stream);
212+
# let (mut sender, conn) = hyper::client::conn::http1::handshake(io).await?;
198213
# tokio::task::spawn(async move {
199214
# if let Err(err) = conn.await {
200215
# println!("Connection failed: {:?}", err);

_stable/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ You can start using it by first adding it to your `Cargo.toml`:
1313

1414
```toml
1515
[dependencies]
16-
hyper = { version = "1.0.0-rc.3", features = ["full"] }
16+
hyper = { version = "1.0.0-rc.4", features = ["full"] }
1717
```
1818

1919
- If building a web server, continue with the [Server guide][].

_stable/server/hello-world.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ First we need to declare our dependencies, let's add the following to our `Cargo
99

1010
```toml
1111
[dependencies]
12-
hyper = { version = "1.0.0-rc.3", features = ["full"] }
12+
hyper = { version = "1.0.0-rc.4", features = ["full"] }
1313
tokio = { version = "1", features = ["full"] }
14-
http-body-util = "0.1.0-rc.2"
14+
http-body-util = "0.1.0-rc.3"
15+
hyper-util = { git = "https://github.com/hyperium/hyper-util.git" }
1516
```
1617

1718
Next, we need to add some imports in our `main.rs` file:
@@ -20,6 +21,7 @@ Next, we need to add some imports in our `main.rs` file:
2021
# extern crate tokio;
2122
# extern crate hyper;
2223
# extern crate http_body_util;
24+
# extern crate hyper_util;
2325
use std::convert::Infallible;
2426
use std::net::SocketAddr;
2527

@@ -28,6 +30,7 @@ use hyper::body::Bytes;
2830
use hyper::server::conn::http1;
2931
use hyper::service::service_fn;
3032
use hyper::{Request, Response};
33+
use hyper_util::rt::TokioIo;
3134
use tokio::net::TcpListener;
3235
# fn main() {}
3336
```
@@ -72,6 +75,7 @@ We'll dive in to the specifics of some of these things in another guide.
7275
# extern crate tokio;
7376
# extern crate hyper;
7477
# extern crate http_body_util;
78+
# extern crate hyper_util;
7579
# mod no_run {
7680
# use std::convert::Infallible;
7781
# use std::net::SocketAddr;
@@ -81,6 +85,7 @@ We'll dive in to the specifics of some of these things in another guide.
8185
# use hyper::server::conn::http1;
8286
# use hyper::service::service_fn;
8387
# use hyper::{Request, Response};
88+
# use hyper_util::rt::TokioIo;
8489
# use tokio::net::TcpListener;
8590
# async fn hello(
8691
# _: Request<hyper::body::Incoming>,
@@ -98,12 +103,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
98103
loop {
99104
let (stream, _) = listener.accept().await?;
100105

106+
// Use an adapter to access something implementing `tokio::io` traits as if they implement
107+
// `hyper::rt` IO traits.
108+
let io = TokioIo::new(stream);
109+
101110
// Spawn a tokio task to serve multiple connections concurrently
102111
tokio::task::spawn(async move {
103112
// Finally, we bind the incoming connection to our `hello` service
104113
if let Err(err) = http1::Builder::new()
105114
// `service_fn` converts our function in a `Service`
106-
.serve_connection(stream, service_fn(hello))
115+
.serve_connection(io, service_fn(hello))
107116
.await
108117
{
109118
println!("Error serving connection: {:?}", err);

0 commit comments

Comments
 (0)