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

Call Interceptor functionality #785

Closed
adriantabirta opened this issue May 8, 2020 · 10 comments
Closed

Call Interceptor functionality #785

adriantabirta opened this issue May 8, 2020 · 10 comments
Labels
kind/enhancement Improvements to existing feature.

Comments

@adriantabirta
Copy link

On client side I need an interceptor, would be great if we do have one like in go

@MrMage MrMage changed the title Still missing interceptors Call Interceptor functionality May 8, 2020
@MrMage MrMage added kind/enhancement Improvements to existing feature. nio labels May 8, 2020
@glbrntt
Copy link
Collaborator

glbrntt commented May 11, 2020

@adriantabirta what's your specific use case? It might be something we can solve without interceptors. I agree though, interceptors would be helpful!

@adriantabirta
Copy link
Author

adriantabirta commented May 13, 2020

I would use Interceptors for:

  • auth - (server side check auth token, client side to get a token/refresh)
  • metrics - (server side)
  • stream filter/validation - (probably most for server side)

@glbrntt glbrntt removed the nio label Jul 6, 2020
@whilesoftware
Copy link

whilesoftware commented Jul 27, 2020

@glbrntt is this on the roadmap?

I'd love to take a stab at implementing it. I was thinking of creating a mechanism to specify additional ChannelHandlers per-Server and/or per-CallHandlerProvider to be injected into the Pipeline between GRPCServerRequestRoutingHandler and BaseCallHandler.

The API would look something like:

extension CallHandlerProvider {
  public var prefixedHandlers: [ChannelHandler.Type]? { get }
}

extension Server.Builder {
  @discardableResult
  public func withPrefixHandlers(_ handlers: [ChannelHandler.Type]) -> Self {
    // prefixedHandlers gets added to Server.Configuration
    self.prefixedHandlers = handlers
    return self
  }
}

Does that sound right?

This would work nicely for my needs, where I want to validate JWT on a subset of my GRPC api. I can currently implement that validation inside a CallHandlerProvider, but that gets ugly quick. The JWT validation is an async operation, but I need to respond synchronously with either a FailedFuture or SucceededFuture, so I'm forced to mark every request as Succeeded and move error handling into my proto service/message layer.

@whilesoftware
Copy link

Actually now I realize the async part of my JWT auth procedure can be factored out... so I suppose this isn't nearly as dire as I was making out.

Still up for contributing if this approach is sane :)

@glbrntt
Copy link
Collaborator

glbrntt commented Jul 28, 2020

It's certainly on the roadmap. It's not clear to me that a ChannelHandler is the right abstraction here though. We need to explore this space some more before deciding on a solution.

@glbrntt
Copy link
Collaborator

glbrntt commented Nov 26, 2020

This is available as of 1.0.0-alpha.21

@glbrntt glbrntt closed this as completed Nov 26, 2020
@zsmatrix62
Copy link

how can I use the ClientInterceptor? any documentations?

@glbrntt
Copy link
Collaborator

glbrntt commented Nov 26, 2020

I have an example/tutorial which needs tidying up, I'll try to post it in the next couple of days. In the meantime I'd suggesting looking at some of the tests as a starting point: https://github.com/grpc/grpc-swift/blob/main/Tests/GRPCTests/InterceptorsTests.swift#L298-#L325

@zsmatrix62
Copy link

I have an example/tutorial which needs tidying up, I'll try to post it in the next couple of days. In the meantime I'd suggesting looking at some of the tests as a starting point: https://github.com/grpc/grpc-swift/blob/main/Tests/GRPCTests/InterceptorsTests.swift#L298-#L325

thanks.

@glbrntt
Copy link
Collaborator

glbrntt commented Dec 14, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements to existing feature.
Projects
None yet
Development

No branches or pull requests

5 participants