forked from hyperium/tonic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce GrpcWebLayer implementing tower::Layer. Fix hyperium#1117
Signed-off-by: slinkydeveloper <[email protected]>
- Loading branch information
1 parent
60c0c54
commit fb2fe58
Showing
5 changed files
with
47 additions
and
18 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
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)] | ||
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
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