C#: allow dot in metadata keys

pull/16444/head
Jan Tattermusch 6 years ago
parent 77b7133244
commit a80fa8732f
  1. 2
      src/csharp/Grpc.Core.Tests/MetadataTest.cs
  2. 4
      src/csharp/Grpc.Core/Metadata.cs

@ -66,6 +66,8 @@ namespace Grpc.Core.Tests
new Metadata.Entry("0123456789abc", "XYZ");
new Metadata.Entry("-abc", "XYZ");
new Metadata.Entry("a_bc_", "XYZ");
new Metadata.Entry("abc.xyz", "XYZ");
new Metadata.Entry("abc.xyz-bin", new byte[] {1, 2, 3});
Assert.Throws(typeof(ArgumentException), () => new Metadata.Entry("abc[", "xyz"));
Assert.Throws(typeof(ArgumentException), () => new Metadata.Entry("abc/", "xyz"));
}

@ -225,7 +225,7 @@ namespace Grpc.Core
/// </summary>
public class Entry
{
private static readonly Regex ValidKeyRegex = new Regex("^[a-z0-9_-]+$");
private static readonly Regex ValidKeyRegex = new Regex("^[.a-z0-9_-]+$");
readonly string key;
readonly string value;
@ -360,7 +360,7 @@ namespace Grpc.Core
{
var normalized = GrpcPreconditions.CheckNotNull(key, "key").ToLowerInvariant();
GrpcPreconditions.CheckArgument(ValidKeyRegex.IsMatch(normalized),
"Metadata entry key not valid. Keys can only contain lowercase alphanumeric characters, underscores and hyphens.");
"Metadata entry key not valid. Keys can only contain lowercase alphanumeric characters, underscores, hyphens and dots.");
return normalized;
}

Loading…
Cancel
Save