-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement tower::Layer for tonic_web::Config #1119
Conversation
Perhaps one question @LucioFranco, should we document it somewhere in the rustdocs of the method |
let svc = tonic_web::config() | ||
.allow_origins(vec![allowed_origin]) | ||
.enable(TestServer::new(Svc)); | ||
let tonic_web_config = tonic_web::config().allow_origins(vec![allowed_origin]); | ||
|
||
let _ = tokio::spawn(async move { | ||
Server::builder() | ||
.accept_http1(true) | ||
.add_service(svc) | ||
.layer(tonic_web_config) | ||
.add_service(TestServer::new(Svc)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I think the idea of adding a layer impl makes sense it feels like the code is actually a bit harder to understand at a glance. So I am inclined to continue to force users through the enabled api. I am curious to hear what @davidpdrsn and @neoeinstein thoughts might be.
@LucioFranco in my case, I'm not using Somehow related to this (but I can open another issue to discuss it), I found out that the CORS code in tonic-web is doing more or less the same of https://docs.rs/tower-http/latest/tower_http/cors/index.html. I was wondering if it makes sense to just expose a GrpcWeb layer that transcodes grpc-web to grpc, and let the tower-http cors implementation handle the cors preflight. So one could either pick the "transcoding layer" manually, or can use |
@slinkydeveloper that seems like an extremely valid argument for the layer stuff. Maybe we should create a Yeah, I think that cors idea is great, we originally had it in here before the one in tower-http was a thing, so more than happy to remove code. Thanks! |
@LucioFranco
WDYT? I can split this work in two or three separate PRs as well (perhaps keeping |
Yeah, that sounds like a great plan, smaller separate PRs will make my life much easier! This all sounds good to me. Thank you! |
Signed-off-by: slinkydeveloper <[email protected]>
Signed-off-by: slinkydeveloper <[email protected]>
@LucioFranco I think this PR as it is should be fine now. I'm working on the second PR to reimplement cors using |
Signed-off-by: slinkydeveloper <[email protected]>
fb2fe58
to
4b20717
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM just one question
Signed-off-by: slinkydeveloper <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect! Thanks!
NamedService
bound fortonic_web::enable
#1115tower::Layer
fortonic_web::Config
#1117