Skip to content

Commit

Permalink
chore: Refactor convert Status to http::Response (#1721)
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto committed Jun 11, 2024
1 parent dfa0893 commit d1558bd
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions tonic/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BoxBody> {
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
}
}

Expand Down

0 comments on commit d1558bd

Please sign in to comment.