|
|
|
@ -36,6 +36,7 @@ using System.Collections.Specialized; |
|
|
|
|
using System.Globalization; |
|
|
|
|
using System.Runtime.InteropServices; |
|
|
|
|
using System.Text; |
|
|
|
|
using System.Text.RegularExpressions; |
|
|
|
|
|
|
|
|
|
using Grpc.Core.Utils; |
|
|
|
|
|
|
|
|
@ -189,6 +190,7 @@ namespace Grpc.Core |
|
|
|
|
public struct Entry |
|
|
|
|
{ |
|
|
|
|
private static readonly Encoding Encoding = Encoding.ASCII; |
|
|
|
|
private static readonly Regex ValidKeyRegex = new Regex("^[a-z0-9_-]+$"); |
|
|
|
|
|
|
|
|
|
readonly string key; |
|
|
|
|
readonly string value; |
|
|
|
@ -321,7 +323,10 @@ namespace Grpc.Core |
|
|
|
|
|
|
|
|
|
private static string NormalizeKey(string key) |
|
|
|
|
{ |
|
|
|
|
return Preconditions.CheckNotNull(key, "key").ToLower(CultureInfo.InvariantCulture); |
|
|
|
|
var normalized = Preconditions.CheckNotNull(key, "key").ToLower(CultureInfo.InvariantCulture); |
|
|
|
|
Preconditions.CheckArgument(ValidKeyRegex.IsMatch(normalized), |
|
|
|
|
"Metadata entry key not valid. Keys can only contain lowercase alphanumeric characters, underscores and hyphens."); |
|
|
|
|
return normalized; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|