chore(dependencies): update to http-body 0.3
This commit is contained in:
@@ -25,7 +25,7 @@ futures-core = { version = "0.3", default-features = false }
|
|||||||
futures-channel = "0.3"
|
futures-channel = "0.3"
|
||||||
futures-util = { version = "0.3", default-features = false }
|
futures-util = { version = "0.3", default-features = false }
|
||||||
http = "0.2"
|
http = "0.2"
|
||||||
http-body = "0.2"
|
http-body = "0.3"
|
||||||
httparse = "1.0"
|
httparse = "1.0"
|
||||||
h2 = "0.2"
|
h2 = "0.2"
|
||||||
itoa = "0.4.1"
|
itoa = "0.4.1"
|
||||||
@@ -49,7 +49,7 @@ spmc = "0.3"
|
|||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
serde_json = "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"
|
tokio-test = "0.2"
|
||||||
url = "1.0"
|
url = "1.0"
|
||||||
|
|
||||||
|
|||||||
@@ -319,7 +319,7 @@ impl Opts {
|
|||||||
async {
|
async {
|
||||||
let res = fut.await.expect("client wait");
|
let res = fut.await.expect("client wait");
|
||||||
let mut body = res.into_body();
|
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 {
|
.serve(make_service_fn( move |_| async move {
|
||||||
Ok::<_, hyper::Error>(service_fn(move |req: Request<Body>| async move {
|
Ok::<_, hyper::Error>(service_fn(move |req: Request<Body>| async move {
|
||||||
let mut req_body = req.into_body();
|
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)))
|
Ok::<_, hyper::Error>(Response::new(Body::from(body)))
|
||||||
}))
|
}))
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::io::{self, Write};
|
|
||||||
|
|
||||||
use hyper::{Client, body::HttpBody as _};
|
use hyper::{Client, body::HttpBody as _};
|
||||||
|
use tokio::io::{self, AsyncWriteExt as _};
|
||||||
|
|
||||||
// A simple type alias so as to DRY.
|
// A simple type alias so as to DRY.
|
||||||
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
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<()> {
|
async fn fetch_url(url: hyper::Uri) -> Result<()> {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
|
|
||||||
let res = client.get(url).await?;
|
let mut res = client.get(url).await?;
|
||||||
|
|
||||||
println!("Response: {}", res.status());
|
println!("Response: {}", res.status());
|
||||||
println!("Headers: {:#?}\n", res.headers());
|
println!("Headers: {:#?}\n", res.headers());
|
||||||
|
|
||||||
let mut body = res.into_body();
|
while let Some(next) = res.body_mut().data().await {
|
||||||
|
|
||||||
while let Some(next) = body.next().await {
|
|
||||||
let chunk = next?;
|
let chunk = next?;
|
||||||
io::stdout().write_all(&chunk)?;
|
io::stdout().write_all(&chunk).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("\n\nDone!");
|
println!("\n\nDone!");
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
//! // Concatenate the body stream into a single buffer...
|
//! // Concatenate the body stream into a single buffer...
|
||||||
//! let mut body = res.into_body();
|
//! let mut body = res.into_body();
|
||||||
//! let mut bytes = Vec::new();
|
//! let mut bytes = Vec::new();
|
||||||
//! while let Some(next) = body.next().await {
|
//! while let Some(next) = body.data().await {
|
||||||
//! let chunk = next?;
|
//! let chunk = next?;
|
||||||
//! bytes.extend(chunk);
|
//! bytes.extend(chunk);
|
||||||
//! }
|
//! }
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ use tokio::runtime::Runtime;
|
|||||||
use tokio::io::{AsyncRead, AsyncWrite};
|
use tokio::io::{AsyncRead, AsyncWrite};
|
||||||
|
|
||||||
use hyper::{Body, Request, Response, StatusCode, Version};
|
use hyper::{Body, Request, Response, StatusCode, Version};
|
||||||
|
use hyper::body::HttpBody as _;
|
||||||
use hyper::client::Client;
|
use hyper::client::Client;
|
||||||
use hyper::server::conn::Http;
|
use hyper::server::conn::Http;
|
||||||
use hyper::server::Server;
|
use hyper::server::Server;
|
||||||
@@ -1779,7 +1780,7 @@ impl tower_service::Service<Request<Body>> for TestService {
|
|||||||
let replies = self.reply.clone();
|
let replies = self.reply.clone();
|
||||||
|
|
||||||
Box::pin(async move {
|
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 {
|
match chunk {
|
||||||
Ok(chunk) => {
|
Ok(chunk) => {
|
||||||
tx.send(Msg::Chunk(chunk.to_vec())).unwrap();
|
tx.send(Msg::Chunk(chunk.to_vec())).unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user