tonic
tonic copied to clipboard
Using (named) interceptors changes the request type from gRPC proto to HTTP (?) when upgrading tonic 0.4->0.5.2
Bug Report
Version
├── tonic v0.5.2 └── tonic-build v0.5.2
Platform
64 bit Windows
Crates
tonic
Description
My old code:
let mut client = Some(
my_service::MyService::with_interceptor(
channel,
move |mut req: Request<()>| {
req.metadata_mut()
.insert("authorization", token_header.clone());
Ok(req)
},
),
);
my new code:
#[derive(Clone)]
struct AuthBearerInterceptor {
auth_header: MetadataValue<Ascii>,
}
impl tonic::service::Interceptor for AuthBearerInterceptor {
fn call(&mut self, request: tonic::Request<()>) -> Result<tonic::Request<()>, tonic::Status> {
let mut result = tonic::Request::new(request.into_inner());
result
.metadata_mut()
.insert("authorization", self.auth_header.clone());
Ok(result)
}
}
...
let mut client = Some(
my_service::MyService::with_interceptor(
channel,
AuthBearerInterceptor { auth_header },
),
);
Request against my Go server break after upgrading and changing to a named interceptor however. Here is what requests looked like with 0.4 when it worked:
{"file":"external/com_github_grpc_ecosystem_go_grpc_middleware/logging/logrus/options.go:211","func":"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus.DefaultMessageProducer","grpc.code":"OK","grpc.method":"FindJiraTasks","grpc.service":"my_service.MyService","grpc.start_time":"2021-08-11T ││ 12:06:18Z","grpc.time_ms":961.586,"level":"info","msg":"finished unary call with code OK","peer.address":"<snip>","span.kind":"server","system":"grpc","time":"2021-08-11T12:06:19Z"}
Here is what it looks like with 0.5.2. and the above new code:
{"content_length":-1,"elapsed":"0.022 ms","file":"lib/embark-server/go/middleware/middleware.go:97","func":"github.com/<snip>/middleware.Logger.func1.1","level":"info","method":"POST","msg":"request processed","path":"/my_service.MyService/FindJiraTasks","protocol":"HT ││ TP/2.0","remote_address":"<snip>","status":404,"time":"2021-08-11T12:04:45Z"}
It appears my server gets an entirely different request type if I use an interceptor. If I do set headers directly on the request however, everything works fine.
I've tried to reproduce this but without luck.
@phoglund Are you able to log the request HTTP version, method, uri, and headers with and without the client interceptor, as its received by the go server? I'm curious about where they differ.