Update StatusBody to support gRPC trailers
Change StatusBody from a tuple struct to a struct containing both data and trailers. Update the codegen to use the new StatusBody::new constructor to specify gRPC status codes. Also remove the temp_test_project.
This commit is contained in:
@@ -12,3 +12,4 @@ http-body = "1.0"
|
||||
http-body-util = "0.1"
|
||||
tower = "0.4"
|
||||
futures-util = "0.3"
|
||||
http = "1.1"
|
||||
|
||||
+18
-2
@@ -101,7 +101,21 @@ impl BufferPool {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct StatusBody(pub Option<Bytes>);
|
||||
pub struct StatusBody {
|
||||
pub data: Option<Bytes>,
|
||||
pub trailers: Option<http::HeaderMap>,
|
||||
}
|
||||
|
||||
impl StatusBody {
|
||||
pub fn new(data: Option<Bytes>, status: u8) -> Self {
|
||||
let mut trailers = http::HeaderMap::new();
|
||||
trailers.insert("grpc-status", status.to_string().parse().unwrap());
|
||||
Self {
|
||||
data,
|
||||
trailers: Some(trailers),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Body for StatusBody {
|
||||
type Data = Bytes;
|
||||
@@ -111,8 +125,10 @@ impl Body for StatusBody {
|
||||
mut self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
) -> Poll<Option<Result<http_body::Frame<Self::Data>, Self::Error>>> {
|
||||
if let Some(data) = self.0.take() {
|
||||
if let Some(data) = self.data.take() {
|
||||
Poll::Ready(Some(Ok(http_body::Frame::data(data))))
|
||||
} else if let Some(trailers) = self.trailers.take() {
|
||||
Poll::Ready(Some(Ok(http_body::Frame::trailers(trailers))))
|
||||
} else {
|
||||
Poll::Ready(None)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user