Skip to content

Commit 51b45e3

Browse files
authoredDec 29, 2022
feat(body): upgrade to http-body 1.0.0-rc.2 (#3106)
1 parent 468b9af commit 51b45e3

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed
 

‎Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ futures-core = { version = "0.3", default-features = false }
2424
futures-channel = "0.3"
2525
futures-util = { version = "0.3", default-features = false }
2626
http = "0.2"
27-
http-body = "1.0.0-rc.1"
28-
http-body-util = { version = "0.1.0-rc.1", optional = true }
27+
http-body = "=1.0.0-rc.2"
28+
http-body-util = { version = "=0.1.0-rc.2", optional = true }
2929
httpdate = "1.0"
3030
httparse = "1.8"
3131
h2 = { version = "0.3.9", optional = true }
@@ -42,7 +42,7 @@ socket2 = { version = "0.4", optional = true }
4242

4343
[dev-dependencies]
4444
futures-util = { version = "0.3", default-features = false, features = ["alloc"] }
45-
http-body-util = "0.1.0-rc.1"
45+
http-body-util = "=0.1.0-rc.2"
4646
matches = "0.1"
4747
num_cpus = "1.0"
4848
pretty_env_logger = "0.4"

‎examples/echo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async fn echo(
2727
// Convert to uppercase before sending back to client using a stream.
2828
(&Method::POST, "/echo/uppercase") => {
2929
let frame_stream = req.into_body().map_frame(|frame| {
30-
let frame = if let Some(data) = frame.into_data() {
30+
let frame = if let Ok(data) = frame.into_data() {
3131
data.iter()
3232
.map(|byte| byte.to_ascii_uppercase())
3333
.collect::<Bytes>()

‎src/ffi/body.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ ffi_fn! {
6363
loop {
6464
match body.0.frame().await {
6565
Some(Ok(frame)) => {
66-
if frame.is_data() {
67-
return Ok(Some(hyper_buf(frame.into_data().unwrap())));
66+
if let Ok(data) = frame.into_data() {
67+
return Ok(Some(hyper_buf(data)));
6868
} else {
6969
continue;
7070
}
@@ -95,7 +95,7 @@ ffi_fn! {
9595
Box::into_raw(hyper_task::boxed(async move {
9696
while let Some(item) = body.0.frame().await {
9797
let frame = item?;
98-
if let Some(chunk) = frame.into_data() {
98+
if let Ok(chunk) = frame.into_data() {
9999
if HYPER_ITER_CONTINUE != func(userdata.0, &hyper_buf(chunk)) {
100100
return Err(crate::Error::new_user_aborted_by_callback());
101101
}

‎src/proto/h1/dispatch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ where
339339
*clear_body = true;
340340
crate::Error::new_user_body(e)
341341
})?;
342-
let chunk = if frame.is_data() {
343-
frame.into_data().unwrap()
342+
let chunk = if let Ok(data) = frame.into_data() {
343+
data
344344
} else {
345345
trace!("discarding non-data frame");
346346
continue;

‎src/proto/h2/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ where
156156
match ready!(me.stream.as_mut().poll_frame(cx)) {
157157
Some(Ok(frame)) => {
158158
if frame.is_data() {
159-
let chunk = frame.into_data().unwrap();
159+
let chunk = frame.into_data().unwrap_or_else(|_| unreachable!());
160160
let is_eos = me.stream.is_end_stream();
161161
trace!(
162162
"send body chunk: {} bytes, eos={}",
@@ -176,7 +176,7 @@ where
176176
// no more DATA, so give any capacity back
177177
me.body_tx.reserve_capacity(0);
178178
me.body_tx
179-
.send_trailers(frame.into_trailers().unwrap())
179+
.send_trailers(frame.into_trailers().unwrap_or_else(|_| unreachable!()))
180180
.map_err(crate::Error::new_body_write)?;
181181
return Poll::Ready(Ok(()));
182182
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.