xref: /tonic/tonic-web/src/layer.rs (revision c8754f3a)
1 use super::{BoxBody, BoxError, GrpcWebService};
2 
3 use tower_layer::Layer;
4 use tower_service::Service;
5 
6 /// Layer implementing the grpc-web protocol.
7 #[derive(Debug, Default, Clone)]
8 pub struct GrpcWebLayer {
9     _priv: (),
10 }
11 
12 impl GrpcWebLayer {
13     /// Create a new grpc-web layer.
14     pub fn new() -> GrpcWebLayer {
15         Self::default()
16     }
17 }
18 
19 impl<S> Layer<S> for GrpcWebLayer
20 where
21     S: Service<http::Request<BoxBody>, Response = http::Response<BoxBody>>,
22     S: Send + 'static,
23     S::Future: Send + 'static,
24     S::Error: Into<BoxError> + Send,
25 {
26     type Service = GrpcWebService<S>;
27 
28     fn layer(&self, inner: S) -> Self::Service {
29         GrpcWebService::new(inner)
30     }
31 }
32