From d1558bdcb5c9c10f1d56ddcb5e73a6b4f18c6b6d Mon Sep 17 00:00:00 2001 From: tottoto Date: Tue, 11 Jun 2024 16:26:53 +0900 Subject: [PATCH] chore: Refactor convert Status to http::Response (#1721) --- tonic/src/status.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tonic/src/status.rs b/tonic/src/status.rs index 4ce3abde6..108ee3cf2 100644 --- a/tonic/src/status.rs +++ b/tonic/src/status.rs @@ -589,16 +589,13 @@ impl Status { #[allow(clippy::wrong_self_convention)] /// Build an `http::Response` from the given `Status`. pub fn to_http(self) -> http::Response { - let (mut parts, _body) = http::Response::new(()).into_parts(); - - parts.headers.insert( + let mut response = http::Response::new(crate::body::empty_body()); + response.headers_mut().insert( http::header::CONTENT_TYPE, http::header::HeaderValue::from_static("application/grpc"), ); - - self.add_header(&mut parts.headers).unwrap(); - - http::Response::from_parts(parts, crate::body::empty_body()) + self.add_header(response.headers_mut()).unwrap(); + response } }