From eaa81dd40212a78b2f7c1136d251b789d0cfb088 Mon Sep 17 00:00:00 2001 From: tottoto Date: Sat, 26 Oct 2024 06:07:48 +0900 Subject: [PATCH] chore: Avoid duplicate box on constructing BoxBody (#2009) --- tonic/src/body.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tonic/src/body.rs b/tonic/src/body.rs index 5e5ba2c54..78d236d42 100644 --- a/tonic/src/body.rs +++ b/tonic/src/body.rs @@ -11,7 +11,14 @@ where B: http_body::Body + Send + 'static, B::Error: Into, { - body.map_err(crate::Status::map_error).boxed_unsync() + let mut body = Some(body); + if let Some(body) = ::downcast_mut::>(&mut body) { + body.take().unwrap() + } else { + body.unwrap() + .map_err(crate::Status::map_error) + .boxed_unsync() + } } /// Create an empty `BoxBody`