Skip to content

Conversation

gjcairo
Copy link
Collaborator

@gjcairo gjcairo commented Nov 13, 2024

Motivation

We want to allow users to customise the RPCs a registered interceptor should apply to on the client:

  • Intercept all requests
  • Intercept requests only meant for specific services
  • Intercept requests only meant for specific methods

Modifications

This PR adds a new ClientInterceptorPipelineOperation type that allows users to specify what the target of the interceptor should be.
Existing APIs accepting [any ClientInterceptor] have been kept, but new initialisers taking [ClientInterceptorPipelineOperation] instead have been added.

Result

Users can have more control over to which requests interceptors are applied.

@gjcairo gjcairo added the ⚠️ semver/major Breaks existing public API. label Nov 13, 2024
@gjcairo gjcairo requested a review from glbrntt November 13, 2024 16:51
/// interceptor added will be the final interceptor to intercept each request before calling
/// the appropriate handler.
private let interceptors: [any ClientInterceptor]
private let interceptorsPerMethod: Mutex<[MethodDescriptor: [any ClientInterceptor]]>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this caching could be useful to speed things up, similar to what we do in the RPCRouter on the server. However I wonder if we care more about the client not taking up too much space (which could be the case if it calls many methods and this dictionary grows a lot).

@gjcairo gjcairo requested a review from glbrntt November 15, 2024 09:23
@gjcairo gjcairo requested a review from glbrntt November 15, 2024 10:11
@glbrntt glbrntt enabled auto-merge (squash) November 15, 2024 10:29
@gjcairo gjcairo force-pushed the service-specific-client-interceptors branch from 0329e42 to 2bf4d02 Compare November 15, 2024 10:59
@glbrntt glbrntt merged commit e160fd0 into grpc:main Nov 15, 2024
43 of 45 checks passed
@gjcairo gjcairo deleted the service-specific-client-interceptors branch November 15, 2024 11:04
@rnro rnro mentioned this pull request Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚠️ semver/major Breaks existing public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants