Skip to content

Commit

Permalink
feat: Make CallSettings.FromGoogleRequestParamsHeader public
Browse files Browse the repository at this point in the history
Fixes #733.

We don't validate that parameters have already been URI-encoded, but
that's probably okay - if callers pass in bad data, we'll just be
sending bad headers, which could be done by callers anyway. In
reality, we're not expecting this to be used outside our own client
libraries, as noted in remarks.
  • Loading branch information
jskeet committed Nov 7, 2023
1 parent 3a37991 commit 6449aa5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Google.Api.Gax.Grpc/CallSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,21 +242,31 @@ public static CallSettings FromFieldMask(string fieldMask)
/// Creates a <see cref="CallSettings"/> which applies an x-goog-request-params header with the specified
/// parameter name and value.
/// </summary>
/// <remarks>The value is URL-encoded; it is expected that <paramref name="parameterName"/> is already URL-encoded.</remarks>
/// <remarks>
/// <para>
/// The value is URL-encoded; it is expected that <paramref name="parameterName"/> is already URL-encoded.
/// </para>
/// <para>
/// This method is intended to be called from API-specific client libraries; it would be very unusual
/// for it to be appropriate to call from application code.
/// </para>
/// </remarks>
/// <param name="parameterName">The name of the parameter. Must not be null.</param>
/// <param name="value">The value of the parameter, which may be null. A null value is equivalent to providing an empty string.</param>
/// <returns>A <see cref="CallSettings"/> which applies the appropriate header with a single parameter.</returns>
internal static CallSettings FromGoogleRequestParamsHeader(string parameterName, string value) =>
public static CallSettings FromGoogleRequestParamsHeader(string parameterName, string value) =>
FromHeader(RequestParamsHeader, parameterName + "=" + Uri.EscapeDataString(value ?? ""));

/// <summary>
/// Creates a <see cref="CallSettings"/> which applies an x-goog-request-params header with the specified
/// escaped header value.
/// </summary>
/// <remarks>This method is intended to be called from API-specific client libraries; it would be very unusual
/// for it to be appropriate to call from application code.</remarks>
/// <param name="escapedHeaderValue">The value of the x-goog-request-params header.
/// Must be escaped. Must not be null or empty.</param>
/// <returns>A <see cref="CallSettings"/> which applies the appropriate header.</returns>
internal static CallSettings FromGoogleRequestParamsHeader(string escapedHeaderValue) =>
public static CallSettings FromGoogleRequestParamsHeader(string escapedHeaderValue) =>
FromHeader(RequestParamsHeader, GaxPreconditions.CheckNotNullOrEmpty(escapedHeaderValue, nameof(escapedHeaderValue)));

/// <summary>
Expand Down

0 comments on commit 6449aa5

Please sign in to comment.