chore(dependencies): update to http-body 0.3

This commit is contained in:
Sean McArthur
2019-12-04 16:29:58 -08:00
parent 4d7a2266b8
commit a738d03fd3
5 changed files with 11 additions and 12 deletions

View File

@@ -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"

View File

@@ -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<Body>| 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)))
}))
}))

View File

@@ -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<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
@@ -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!");

View File

@@ -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);
//! }

View File

@@ -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<Request<Body>> 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();