MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / isValidGRPCMetadataKey

Function isValidGRPCMetadataKey

runtime/context.go:104–121  ·  view source on GitHub ↗
(key string)

Source from the content-addressed store, hash-verified

102}
103
104func isValidGRPCMetadataKey(key string) bool {
105 // Must be a valid gRPC "Header-Name" as defined here:
106 // https://github.com/grpc/grpc/blob/4b05dc88b724214d0c725c8e7442cbc7a61b1374/doc/PROTOCOL-HTTP2.md
107 // This means 0-9 a-z _ - .
108 // Only lowercase letters are valid in the wire protocol, but the client library will normalize
109 // uppercase ASCII to lowercase, so uppercase ASCII is also acceptable.
110 bytes := []byte(key) // gRPC validates strings on the byte level, not Unicode.
111 for _, ch := range bytes {
112 validLowercaseLetter := ch >= 'a' && ch <= 'z'
113 validUppercaseLetter := ch >= 'A' && ch <= 'Z'
114 validDigit := ch >= '0' && ch <= '9'
115 validOther := ch == '.' || ch == '-' || ch == '_'
116 if !validLowercaseLetter && !validUppercaseLetter && !validDigit && !validOther {
117 return false
118 }
119 }
120 return true
121}
122
123func isValidGRPCMetadataTextValue(textValue string) bool {
124 // Must be a valid gRPC "ASCII-Value" as defined here:

Callers 1

annotateContextFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected