Skip to content

Commit

Permalink
feat: Add formatting method for routing header values
Browse files Browse the repository at this point in the history
This will then be called by the generator for both implicit and explicit headers that are not for string fields.

It's slightly annoying to have to include a type name when calling
the method, but it's only ever used in autogenerated code, and I
think that beats exposing it in a less specific context.

Release-As: 4.2.0-alpha01
  • Loading branch information
jskeet committed Sep 6, 2022
1 parent 69c94c2 commit f4064f9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Google.Api.Gax.Grpc/RoutingHeaderExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Google.Api.Gax.Grpc
Expand Down Expand Up @@ -59,6 +58,16 @@ private RoutingHeaderExtractor(List<SinglePatternExtractor> patternExtractors)
.ToList();
}

/// <summary>
/// Returns a string representation of the given value, suitable for including in a routing header.
/// (This method does not perform URI encoding; it is expected that the result of this method will either be
/// used in <see cref="WithExtractedParameter(string, string, Func{TRequest, string})"/>, or as an argument to
/// <see cref="ApiCall{TRequest, TResponse}.WithGoogleRequestParam(string, Func{TRequest, string})" />.)
/// </summary>
/// <param name="value">The value to format. May be null.</param>
/// <returns>The formatted value, or null if <paramref name="value"/> is null.</returns>
public static string FormatRoutingHeaderValue(object value) => ProtobufUtilities.FormatValueAsJsonPrimitive(value);

/// <summary>
/// Returns a new instance with the same parameter extractors as this one, with an additional one specified as arguments.
/// The extractions follow the "last successfully matched wins" rule for
Expand Down

0 comments on commit f4064f9

Please sign in to comment.