From a738d03fd3fa4bc57360014914105be72ed01069 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Wed, 4 Dec 2019 16:29:58 -0800 Subject: [PATCH] chore(dependencies): update to http-body 0.3 --- Cargo.toml | 4 ++-- benches/end_to_end.rs | 4 ++-- examples/client.rs | 10 ++++------ src/client/mod.rs | 2 +- tests/server.rs | 3 ++- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1e3e7aacaf..456e005fba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ futures-core = { version = "0.3", default-features = false } futures-channel = "0.3" futures-util = { version = "0.3", default-features = false } http = "0.2" -http-body = "0.2" +http-body = "0.3" httparse = "1.0" h2 = "0.2" itoa = "0.4.1" @@ -49,7 +49,7 @@ spmc = "0.3" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" -tokio = { version = "0.2.2", features = ["fs", "macros", "rt-util", "sync", "time", "test-util"] } +tokio = { version = "0.2.2", features = ["fs", "macros", "io-std", "rt-util", "sync", "time", "test-util"] } tokio-test = "0.2" url = "1.0" diff --git a/benches/end_to_end.rs b/benches/end_to_end.rs index 0f217b1645..68ee7f053d 100644 --- a/benches/end_to_end.rs +++ b/benches/end_to_end.rs @@ -319,7 +319,7 @@ impl Opts { async { let res = fut.await.expect("client wait"); let mut body = res.into_body(); - while let Some(_chunk) = body.next().await {} + while let Some(_chunk) = body.data().await {} } }; @@ -356,7 +356,7 @@ fn spawn_server(rt: &mut tokio::runtime::Runtime, opts: &Opts) -> SocketAddr { .serve(make_service_fn( move |_| async move { Ok::<_, hyper::Error>(service_fn(move |req: Request| async move { let mut req_body = req.into_body(); - while let Some(_chunk) = req_body.next().await {} + while let Some(_chunk) = req_body.data().await {} Ok::<_, hyper::Error>(Response::new(Body::from(body))) })) })) diff --git a/examples/client.rs b/examples/client.rs index f488bc8916..f60990e024 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -1,9 +1,9 @@ #![deny(warnings)] #![warn(rust_2018_idioms)] use std::env; -use std::io::{self, Write}; use hyper::{Client, body::HttpBody as _}; +use tokio::io::{self, AsyncWriteExt as _}; // A simple type alias so as to DRY. type Result = std::result::Result>; @@ -35,16 +35,14 @@ async fn main() -> Result<()> { async fn fetch_url(url: hyper::Uri) -> Result<()> { let client = Client::new(); - let res = client.get(url).await?; + let mut res = client.get(url).await?; println!("Response: {}", res.status()); println!("Headers: {:#?}\n", res.headers()); - let mut body = res.into_body(); - - while let Some(next) = body.next().await { + while let Some(next) = res.body_mut().data().await { let chunk = next?; - io::stdout().write_all(&chunk)?; + io::stdout().write_all(&chunk).await?; } println!("\n\nDone!"); diff --git a/src/client/mod.rs b/src/client/mod.rs index 6d0c4b0098..afb7aba9d1 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -42,7 +42,7 @@ //! // Concatenate the body stream into a single buffer... //! let mut body = res.into_body(); //! let mut bytes = Vec::new(); -//! while let Some(next) = body.next().await { +//! while let Some(next) = body.data().await { //! let chunk = next?; //! bytes.extend(chunk); //! } diff --git a/tests/server.rs b/tests/server.rs index c43f4e1ab3..02e3ccf7c8 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -23,6 +23,7 @@ use tokio::runtime::Runtime; use tokio::io::{AsyncRead, AsyncWrite}; use hyper::{Body, Request, Response, StatusCode, Version}; +use hyper::body::HttpBody as _; use hyper::client::Client; use hyper::server::conn::Http; use hyper::server::Server; @@ -1779,7 +1780,7 @@ impl tower_service::Service> for TestService { let replies = self.reply.clone(); Box::pin(async move { - while let Some(chunk) = hyper::body::HttpBody::next(req.body_mut()).await { + while let Some(chunk) = req.body_mut().data().await { match chunk { Ok(chunk) => { tx.send(Msg::Chunk(chunk.to_vec())).unwrap();