From 51b45e3f8580da5667a45395e6622455b10e2ad3 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Thu, 29 Dec 2022 14:36:18 -0500 Subject: [PATCH] feat(body): upgrade to http-body 1.0.0-rc.2 (#3106) --- Cargo.toml | 6 +++--- examples/echo.rs | 2 +- src/ffi/body.rs | 6 +++--- src/proto/h1/dispatch.rs | 4 ++-- src/proto/h2/mod.rs | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 258f103fb5..b2decdb3f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,8 +24,8 @@ 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 = "1.0.0-rc.1" -http-body-util = { version = "0.1.0-rc.1", optional = true } +http-body = "=1.0.0-rc.2" +http-body-util = { version = "=0.1.0-rc.2", optional = true } httpdate = "1.0" httparse = "1.8" h2 = { version = "0.3.9", optional = true } @@ -42,7 +42,7 @@ socket2 = { version = "0.4", optional = true } [dev-dependencies] futures-util = { version = "0.3", default-features = false, features = ["alloc"] } -http-body-util = "0.1.0-rc.1" +http-body-util = "=0.1.0-rc.2" matches = "0.1" num_cpus = "1.0" pretty_env_logger = "0.4" diff --git a/examples/echo.rs b/examples/echo.rs index 3562cd8e25..a644996b3c 100644 --- a/examples/echo.rs +++ b/examples/echo.rs @@ -27,7 +27,7 @@ async fn echo( // Convert to uppercase before sending back to client using a stream. (&Method::POST, "/echo/uppercase") => { let frame_stream = req.into_body().map_frame(|frame| { - let frame = if let Some(data) = frame.into_data() { + let frame = if let Ok(data) = frame.into_data() { data.iter() .map(|byte| byte.to_ascii_uppercase()) .collect::() diff --git a/src/ffi/body.rs b/src/ffi/body.rs index 4cc3415f2b..5a56356d72 100644 --- a/src/ffi/body.rs +++ b/src/ffi/body.rs @@ -63,8 +63,8 @@ ffi_fn! { loop { match body.0.frame().await { Some(Ok(frame)) => { - if frame.is_data() { - return Ok(Some(hyper_buf(frame.into_data().unwrap()))); + if let Ok(data) = frame.into_data() { + return Ok(Some(hyper_buf(data))); } else { continue; } @@ -95,7 +95,7 @@ ffi_fn! { Box::into_raw(hyper_task::boxed(async move { while let Some(item) = body.0.frame().await { let frame = item?; - if let Some(chunk) = frame.into_data() { + if let Ok(chunk) = frame.into_data() { if HYPER_ITER_CONTINUE != func(userdata.0, &hyper_buf(chunk)) { return Err(crate::Error::new_user_aborted_by_callback()); } diff --git a/src/proto/h1/dispatch.rs b/src/proto/h1/dispatch.rs index 81f7014de9..cd494581b9 100644 --- a/src/proto/h1/dispatch.rs +++ b/src/proto/h1/dispatch.rs @@ -339,8 +339,8 @@ where *clear_body = true; crate::Error::new_user_body(e) })?; - let chunk = if frame.is_data() { - frame.into_data().unwrap() + let chunk = if let Ok(data) = frame.into_data() { + data } else { trace!("discarding non-data frame"); continue; diff --git a/src/proto/h2/mod.rs b/src/proto/h2/mod.rs index 620ef33401..a1cbd25813 100644 --- a/src/proto/h2/mod.rs +++ b/src/proto/h2/mod.rs @@ -156,7 +156,7 @@ where match ready!(me.stream.as_mut().poll_frame(cx)) { Some(Ok(frame)) => { if frame.is_data() { - let chunk = frame.into_data().unwrap(); + let chunk = frame.into_data().unwrap_or_else(|_| unreachable!()); let is_eos = me.stream.is_end_stream(); trace!( "send body chunk: {} bytes, eos={}", @@ -176,7 +176,7 @@ where // no more DATA, so give any capacity back me.body_tx.reserve_capacity(0); me.body_tx - .send_trailers(frame.into_trailers().unwrap()) + .send_trailers(frame.into_trailers().unwrap_or_else(|_| unreachable!())) .map_err(crate::Error::new_body_write)?; return Poll::Ready(Ok(())); } else {