Grpc-web: Question: Custom interceptor

Created on 7 Sep 2018  路  8Comments  路  Source: grpc/grpc-web

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)
                }
            }
        }
    }}
enhancement

Most helpful comment

We have plans to add Interceptor support in the future. We will start with an API proposal first.

All 8 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TBoshoven picture TBoshoven  路  4Comments

ivan-sysoi picture ivan-sysoi  路  5Comments

sirudog picture sirudog  路  3Comments

graup picture graup  路  4Comments

aberasarte picture aberasarte  路  6Comments