Skip to content

Commit

Permalink
fix: Set x-goog-request-params for streaming pull requests from Subsc…
Browse files Browse the repository at this point in the history
…riberClient

This is an alternative to #11288, setting a single CallSettings that
is applied to every StreamingPull call.
  • Loading branch information
jskeet committed Nov 3, 2023
1 parent 40744ca commit 7b6ec74
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract partial class SubscriberClient
/// This type is now obsolete; please use <see cref="SubscriberClientBuilder"/> which provides an
/// API surface consistent with other clients (as well as additional Pub/Sub-specific properties such as <see cref="SubscriberClientBuilder.ClientCount"/>).
/// </summary>
[Obsolete("Use PublisherClientBuilder to customize client settings.")]
[Obsolete("Use SubscriberClientBuilder to customize client settings.")]
public sealed class ClientCreationSettings
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,30 @@ static Task DisposeChannelAsync(Grpc.Core.ChannelBase channel)

return channel.ShutdownAsync();
}

}

/// <summary>
/// Returns the *effective* API settings to use, with any additional CallSettings applied.
/// </summary>
internal SubscriberServiceApiSettings GetEffectiveApiSettings()
{
// We should never end up being called without a subscription name, but let's
// be careful anyway. If we don't have a subscription name, we don't need to modify
// the settings.
if (SubscriptionName is not SubscriptionName subscriptionName)
{
return ApiSettings;
}

// We never modify a settings object that the user code has specified explicitly.
var settingsToModify = ApiSettings?.Clone() ?? new SubscriberServiceApiSettings();

// TODO: Use CallSettings.FromGoogleRequestParamsHeader when
// https://github.com/googleapis/gax-dotnet/issues/733 is fixed and released.
settingsToModify.StreamingPullSettings = settingsToModify.StreamingPullSettings
.WithHeader("x-goog-request-params", $"subscription={Uri.EscapeDataString(subscriptionName.ToString())}");
return settingsToModify;
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public new EmulatorDetection EmulatorDetection
internal SubscriberServiceApiClientBuilder(SubscriberClientBuilder otherBuilder, GrpcChannelOptions extraChannelOptions) : this()
{
CopyCommonSettings(otherBuilder);
Settings = otherBuilder.ApiSettings;
Settings = otherBuilder.GetEffectiveApiSettings();
ChannelPoolDisabled = true;
ChannelOptions = extraChannelOptions;
}
Expand Down

0 comments on commit 7b6ec74

Please sign in to comment.