Skip to content

Commit

Permalink
Introduce GrpcWebLayer implementing tower::Layer. Fix hyperium#1117
Browse files Browse the repository at this point in the history
Signed-off-by: slinkydeveloper <francescoguard@gmail.com>
  • Loading branch information
slinkydeveloper committed Oct 31, 2022
1 parent 0b463d7 commit 18e6039
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
15 changes: 0 additions & 15 deletions tonic-web/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::time::Duration;

use http::{header::HeaderName, HeaderValue};
use tonic::body::BoxBody;
use tower_layer::Layer;
use tower_service::Service;

use crate::service::GrpcWeb;
Expand Down Expand Up @@ -165,17 +164,3 @@ impl Default for Config {
Config::new()
}
}

impl<S> Layer<S> for Config
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 {
self.enable(inner)
}
}
7 changes: 4 additions & 3 deletions tonic-web/tests/integration/tests/grpc_web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ async fn spawn(allowed_origin: &str) -> String {
let url = format!("http://{}", listener.local_addr().unwrap());
let listener_stream = TcpListenerStream::new(listener);

let tonic_web_config = tonic_web::config().allow_origins(vec![allowed_origin]);
let svc = tonic_web::config()
.allow_origins(vec![allowed_origin])
.enable(TestServer::new(Svc));

let _ = tokio::spawn(async move {
Server::builder()
.accept_http1(true)
.layer(tonic_web_config)
.add_service(TestServer::new(Svc))
.add_service(svc)
.serve_with_incoming(listener_stream)
.await
.unwrap()
Expand Down

0 comments on commit 18e6039

Please sign in to comment.