Hi,
is it possible to write a custom interceptor?
Can i access the custom metadata?
In kotlin i do something like this:
CustomInterceptor : ServerInterceptor{
private var codeKey: Metadata.Key<Int> = Metadata.Key.of("meta1", IntMarshaller())
private var messageKey: Metadata.Key<String> = Metadata.Key.of("meta2", UTF8Marshaller())
override fun <ReqT : Any?, RespT : Any?> interceptCall(call: ServerCall<ReqT, RespT>?, headers: Metadata?, next: ServerCallHandler<ReqT, RespT>?): ServerCall.Listener<ReqT> {
val delegate = next!!.startCall(call, headers)
return object : SimpleForwardingServerCallListener<ReqT>(delegate) {
override fun onHalfClose() {
call?.close(Status.UNKNOWN, customMetadata)
}
}
}
}}
We have plans to add Interceptor support in the future. We will start with an API proposal first.
Good news! Thx for your feedback!
Prior art: gRPC Node interceptors: https://github.com/grpc/grpc-node/pull/59
Do we have any movement on client interceptors?
Can we take the proposal for Node and port it for grpc-web? https://github.com/grpc/proposal/blob/master/L5-node-client-interceptors.md
As far as I understand client interceptor is necessary for creating a centralized authentication mechanism (one that you don't have to add the auth token to request metadata on each request manually) and also for creating PWA's. Am I right? or is there another way to do these things?
I've submitted a new issue that defines an API Proposal for client interceptors for gRPC-Web #555
Heavily "copy+pasted" from the NodeJS proposal, but have tailored for gRPC-Web and how the current API is structured (ie. the rpcCall and serverStreaming)
Feedback welcome/required.
The way NodeJS native library uses call stacks is very different to the web implementation, so still fleshing out how the InterceptingCall stack will function for this implementation.
This has been implemented yay
Blog post for posterity: https://grpc.io/blog/grpc-web-interceptor/
Most helpful comment
We have plans to add Interceptor support in the future. We will start with an API proposal first.