Skip to content
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

Question: Custom interceptor #283

Closed
nucle opened this issue Sep 7, 2018 · 8 comments
Closed

Question: Custom interceptor #283

nucle opened this issue Sep 7, 2018 · 8 comments

Comments

@nucle
Copy link

nucle commented Sep 7, 2018

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)
                }
            }
        }
    }}
@stanley-cheung
Copy link
Collaborator

stanley-cheung commented Sep 7, 2018

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

@nucle
Copy link
Author

nucle commented Sep 7, 2018

Good news! Thx for your feedback!

@stanley-cheung
Copy link
Collaborator

Prior art: gRPC Node interceptors: grpc/grpc-node#59

@rogchap
Copy link
Contributor

rogchap commented Apr 15, 2019

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

@mmohaveri
Copy link

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?

@rogchap
Copy link
Contributor

rogchap commented May 9, 2019

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.

@stanley-cheung
Copy link
Collaborator

This has been implemented yay

@mfickett
Copy link

Blog post for posterity: https://grpc.io/blog/grpc-web-interceptor/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants