feat(web): Implement tower::Layer for tonic_web::Config (#1119)

Signed-off-by: slinkydeveloper <[email protected]>
This commit is contained in:
Francesco Guardiani
2022-10-28 13:59:01 -04:00
committed by GitHub
parent b409ddd478
commit 40536dc134
5 changed files with 47 additions and 6 deletions
+31
View File
@@ -0,0 +1,31 @@
use super::{BoxBody, BoxError, Config, GrpcWeb};
use tower_layer::Layer;
use tower_service::Service;
/// Layer implementing the grpc-web protocol.
#[derive(Debug, Clone)]
pub struct GrpcWebLayer {
_priv: (),
}
impl GrpcWebLayer {
/// Create a new grpc-web layer.
pub fn new() -> GrpcWebLayer {
Self { _priv: () }
}
}
impl<S> Layer<S> for GrpcWebLayer
where
S: Service<http::Request<hyper::Body>, Response = http::Response<BoxBody>>,
S: Clone + Send + 'static,
S::Future: Send + 'static,
S::Error: Into<BoxError> + Send,
{
type Service = GrpcWeb<S>;
fn layer(&self, inner: S) -> Self::Service {
Config::default().enable(inner)
}
}