diff --git a/src/Google.Api.Gax.Grpc/ApiCall.cs b/src/Google.Api.Gax.Grpc/ApiCall.cs index 0610fbfb..edb4a992 100644 --- a/src/Google.Api.Gax.Grpc/ApiCall.cs +++ b/src/Google.Api.Gax.Grpc/ApiCall.cs @@ -54,10 +54,7 @@ internal ApiCall( private readonly CallSettings _baseCallSettings; private T Call(TRequest request, CallSettings perCallCallSettings, Func fn) - { - CallSettings callSettings = CallSettings.Merge(_baseCallSettings, perCallCallSettings); - return fn(callSettings); - } + => fn(_baseCallSettings.MergedWith(perCallCallSettings)); /// /// Performs an RPC call asynchronously. @@ -80,23 +77,20 @@ public Task Async(TRequest request, CallSettings perCallCallSettings) public TResponse Sync(TRequest request, CallSettings perCallCallSettings) => Call(request, perCallCallSettings, callSettings => _syncCall(request, callSettings)); - internal ApiCall WithUserAgent(string userAgent) - { + internal ApiCall WithUserAgent(string userAgent) => // TODO: Check that this is what we want. It allows call settings to remove our // user agent header. The caller can always do this manually anyway, of course, so // I'm tempted to leave it... - return new ApiCall( + new ApiCall( _asyncCall, _syncCall, - CallSettings.Merge(CallSettings.ForUserAgent(userAgent), _baseCallSettings)); - } + CallSettings.FromHeader(UserAgentBuilder.HeaderName, userAgent) + .MergedWith(_baseCallSettings)); - internal ApiCall WithRetry(IClock clock, IScheduler scheduler) - { - return new ApiCall( + internal ApiCall WithRetry(IClock clock, IScheduler scheduler) => + new ApiCall( _asyncCall.WithRetry(clock, scheduler), _syncCall.WithRetry(clock, scheduler), _baseCallSettings); - } } } diff --git a/src/Google.Api.Gax.Grpc/ApiCallRetryExtensions.cs b/src/Google.Api.Gax.Grpc/ApiCallRetryExtensions.cs index a52bd2c2..87e7c805 100644 --- a/src/Google.Api.Gax.Grpc/ApiCallRetryExtensions.cs +++ b/src/Google.Api.Gax.Grpc/ApiCallRetryExtensions.cs @@ -34,8 +34,7 @@ internal static Func> WithRetry WithRetry WithRetryOriginal settings. May be null. /// Settings to overlay. May be null. /// A merged set of call settings. - public static CallSettings Merge(CallSettings original, CallSettings overlaid) + internal static CallSettings Merge(CallSettings original, CallSettings overlaid) { if (original == null) { @@ -107,12 +107,6 @@ public static CallSettings Merge(CallSettings original, CallSettings overlaid) overlaid.PropagationToken ?? original.PropagationToken); } - /// - /// Creates a for the specified user agent. - /// - internal static CallSettings ForUserAgent(string userAgent) => - FromHeaderMutation(metadata => metadata.Add(UserAgentBuilder.HeaderName, userAgent)); - /// /// Creates a for the specified cancellation token. /// diff --git a/src/Google.Api.Gax.Grpc/CallSettingsExtensions.cs b/src/Google.Api.Gax.Grpc/CallSettingsExtensions.cs index 3d296859..eba2aff3 100644 --- a/src/Google.Api.Gax.Grpc/CallSettingsExtensions.cs +++ b/src/Google.Api.Gax.Grpc/CallSettingsExtensions.cs @@ -16,16 +16,14 @@ namespace Google.Api.Gax.Grpc public static class CallSettingsExtensions { /// - /// Shorthand for calling . - /// - /// /// This method merges the settings in with those in /// , with taking priority. /// If both arguments are null, the result is null. If one argument is null, /// the other argument is returned. Otherwise, a new object is created with a property-wise - /// overlay. Any header mutations are combined, however: the mutation from the original is + /// overlay, where null values do not override non-null values. + /// Any header mutations are combined, however: the mutation from the original is /// performed, then the mutation in the overlay. - /// + /// /// Original settings. May be null. /// Settings to overlay. May be null. /// A merged set of call settings, or null if both parameters are null. diff --git a/src/Google.Api.Gax.Grpc/ClientHelper.cs b/src/Google.Api.Gax.Grpc/ClientHelper.cs index f307212e..c85175a5 100644 --- a/src/Google.Api.Gax.Grpc/ClientHelper.cs +++ b/src/Google.Api.Gax.Grpc/ClientHelper.cs @@ -62,7 +62,7 @@ public ApiCall BuildApiCall( where TRequest : class, IMessage where TResponse : class, IMessage { - CallSettings baseCallSettings = CallSettings.Merge(_clientCallSettings, perMethodCallSettings); + CallSettings baseCallSettings = _clientCallSettings.MergedWith(perMethodCallSettings); // These operations are applied in reverse order. // I.e. User-agent is added first, then retry is performed. return ApiCall.Create(asyncGrpcCall, syncGrpcCall, baseCallSettings, Clock) diff --git a/src/Google.Api.Gax.Grpc/PageStreamingAsync.cs b/src/Google.Api.Gax.Grpc/PageStreamingAsync.cs index 9b5b668c..ec72c0f1 100644 --- a/src/Google.Api.Gax.Grpc/PageStreamingAsync.cs +++ b/src/Google.Api.Gax.Grpc/PageStreamingAsync.cs @@ -107,7 +107,7 @@ public async Task MoveNext(CancellationToken cancellationToken) CallSettings effectiveCallSettings = _callSettings; if (cancellationToken != default(CancellationToken)) { - effectiveCallSettings = CallSettings.Merge(_callSettings, CallSettings.FromCancellationToken(cancellationToken)); + effectiveCallSettings = _callSettings.WithCancellationToken(cancellationToken); } Current = await _apiCall.Async(_request, effectiveCallSettings); var nextPageToken = Current.NextPageToken;