From 4bc49f5c4b9b22c2d90e1933d3223799755c1e81 Mon Sep 17 00:00:00 2001 From: Mehrdad Afshari Date: Sun, 11 Feb 2018 23:19:34 -0800 Subject: [PATCH] Simplify ClientHeaderInterceptor in ClientBase with GenericInterceptor --- src/csharp/Grpc.Core/ClientBase.cs | 50 +++++------------------------- 1 file changed, 7 insertions(+), 43 deletions(-) diff --git a/src/csharp/Grpc.Core/ClientBase.cs b/src/csharp/Grpc.Core/ClientBase.cs index d64ce7dd944..f978d084d98 100644 --- a/src/csharp/Grpc.Core/ClientBase.cs +++ b/src/csharp/Grpc.Core/ClientBase.cs @@ -149,7 +149,7 @@ namespace Grpc.Core /// protected internal class ClientBaseConfiguration { - private class ClientHeaderInterceptor : Interceptor + private class ClientHeaderInterceptor : GenericInterceptor { readonly Func> interceptor; @@ -161,49 +161,13 @@ namespace Grpc.Core this.interceptor = GrpcPreconditions.CheckNotNull(interceptor, "interceptor"); } - /// - /// Intercepts a blocking invocation of a simple remote call. - /// - public override TResponse BlockingUnaryCall(TRequest request, ClientInterceptorContext context, BlockingUnaryCallContinuation continuation) - { - var newHeaders = interceptor(context.Method, context.Host, context.Options); - return continuation(request, new ClientInterceptorContext(context.Method, newHeaders.Item1, newHeaders.Item2)); - } - - /// - /// Intercepts an asynchronous invocation of a simple remote call. - /// - public override AsyncUnaryCall AsyncUnaryCall(TRequest request, ClientInterceptorContext context, AsyncUnaryCallContinuation continuation) - { - var newHeaders = interceptor(context.Method, context.Host, context.Options); - return continuation(request, new ClientInterceptorContext(context.Method, newHeaders.Item1, newHeaders.Item2)); - } - - /// - /// Intercepts an asynchronous invocation of a streaming remote call. - /// - public override AsyncServerStreamingCall AsyncServerStreamingCall(TRequest request, ClientInterceptorContext context, AsyncServerStreamingCallContinuation continuation) - { - var newHeaders = interceptor(context.Method, context.Host, context.Options); - return continuation(request, new ClientInterceptorContext(context.Method, newHeaders.Item1, newHeaders.Item2)); - } - - /// - /// Intercepts an asynchronous invocation of a client streaming call. - /// - public override AsyncClientStreamingCall AsyncClientStreamingCall(ClientInterceptorContext context, AsyncClientStreamingCallContinuation continuation) - { - var newHeaders = interceptor(context.Method, context.Host, context.Options); - return continuation(new ClientInterceptorContext(context.Method, newHeaders.Item1, newHeaders.Item2)); - } - - /// - /// Intercepts an asynchronous invocation of a duplex streaming call. - /// - public override AsyncDuplexStreamingCall AsyncDuplexStreamingCall(ClientInterceptorContext context, AsyncDuplexStreamingCallContinuation continuation) + protected override ClientCallArbitrator InterceptCall(ClientInterceptorContext context, bool clientStreaming, bool serverStreaming, TRequest request) { - var newHeaders = interceptor(context.Method, context.Host, context.Options); - return continuation(new ClientInterceptorContext(context.Method, newHeaders.Item1, newHeaders.Item2)); + var newHostAndCallOptions = interceptor(context.Method, context.Host, context.Options); + return new ClientCallArbitrator + { + Context = new ClientInterceptorContext(context.Method, newHostAndCallOptions.Item1, newHostAndCallOptions.Item2) + }; } }