Skip to content

Commit

Permalink
chore(dependencies): update to http-body 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Dec 5, 2019
1 parent 4d7a226 commit a738d03
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -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"
Expand All @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions benches/end_to_end.rs
Expand Up @@ -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 {}
}
};

Expand Down Expand Up @@ -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)))
}))
}))
Expand Down
10 changes: 4 additions & 6 deletions 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<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
Expand Down Expand Up @@ -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!");
Expand Down
2 changes: 1 addition & 1 deletion src/client/mod.rs
Expand Up @@ -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);
//! }
Expand Down
3 changes: 2 additions & 1 deletion tests/server.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a738d03

Please sign in to comment.