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, 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 { _priv: () } 16 } 17 } 18 19 impl Default for GrpcWebLayer { 20 fn default() -> Self { 21 Self::new() 22 } 23 } 24 25 impl<S> Layer<S> for GrpcWebLayer 26 where 27 S: Service<http::Request<hyper::Body>, Response = http::Response<BoxBody>>, 28 S: Clone + Send + 'static, 29 S::Future: Send + 'static, 30 S::Error: Into<BoxError> + Send, 31 { 32 type Service = GrpcWebService<S>; 33 34 fn layer(&self, inner: S) -> Self::Service { 35 GrpcWebService::new(inner) 36 } 37 } 38