-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): Implement tower::Layer for tonic_web::Config (#1119)
Signed-off-by: slinkydeveloper <[email protected]>
- Loading branch information
1 parent
b409ddd
commit 40536dc
Showing
5 changed files
with
47 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters