-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Use case(s) - what problem will this feature solve?
I would like to write a grpc.XxxClientInterceptor that is able to safely extract and interact with the authority header.
Proposed Solution
Since this information is currently hidden inside grpc.ClientConn, and that struct is an input to the grpc.XxxYyyInterceptor types, it seems reasonable to add a method to extract it.
func (cc *ClientConn) Authority() string {
return cc.authority
}Alternatives Considered
Func
Instead of a method, this could be implemented as a function, but does not read as well.
func Authority(cc *ClientConn) string {
return cc.authority
}Field
Currently authority is immutable, thus thread safe. Exposing a field would be easier than a method, but would break both guarantees.
type ClientConn struct {
Authority string
// ... other fields elided ...
}Parameter
Since both grpc.XxxClientInterceptor types are EXPERIMENTAL APIs, you could just expose the value directly as a parameter. This seems pretty heavy for something that is not always required, and it double embeds the value (authority and cc.authority), so more edge cases and failure modes need be tested.
type UnaryClientInterceptor func(ctx context.Context, method, authority string, req, reply interface{}, cc *ClientConn, invoker UnaryInvoker, opts ...CallOption) error
type StreamClientInterceptor func(ctx context.Context, desc *StreamDesc, cc *ClientConn, method, authority string, streamer Streamer, opts ...CallOption) (ClientStream, error)Additional Context
Authority is an h2 pseudo header set by grpc.WithAuthority. This grpc.DialOption binds the given string to grpc.dialOptions.authority, then grpc.Dial and grpc.DialContext bind against grpc.ClientConn.authority when called.