tower_grpc/server/
unimplemented.rs

1use crate::{Code, Status};
2
3use futures::{Future, Poll};
4use http::header;
5
6#[derive(Debug)]
7pub struct ResponseFuture {
8    status: Option<Status>,
9}
10
11impl ResponseFuture {
12    pub(crate) fn new(msg: String) -> Self {
13        ResponseFuture {
14            status: Some(Status::new(Code::Unimplemented, msg)),
15        }
16    }
17}
18
19impl Future for ResponseFuture {
20    type Item = http::Response<()>;
21    type Error = crate::error::Never;
22
23    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
24        let status = self.status.take().expect("polled after complete");
25
26        // Construct http response
27        let mut response = http::Response::new(());
28
29        // Set the content type
30        // As the rpc is unimplemented we don't care about
31        // specifying the encoding (+proto, +json, +...)
32        // so we can just return a dummy "application/grpc"
33        response.headers_mut().insert(
34            header::CONTENT_TYPE,
35            header::HeaderValue::from_static("application/grpc"),
36        );
37
38        status
39            .add_header(response.headers_mut())
40            .expect("generated unimplemented message should be valid");
41        Ok(response.into())
42    }
43}