MCPcopy
hub / github.com/grpc/grpc-go / ValueFromIncomingContext

Function ValueFromIncomingContext

metadata/metadata.go:216–234  ·  view source on GitHub ↗

ValueFromIncomingContext returns the metadata value corresponding to the metadata key from the incoming metadata if it exists. Keys are matched in a case insensitive manner.

(ctx context.Context, key string)

Source from the content-addressed store, hash-verified

214// key from the incoming metadata if it exists. Keys are matched in a case insensitive
215// manner.
216func ValueFromIncomingContext(ctx context.Context, key string) []string {
217 md, ok := ctx.Value(mdIncomingKey{}).(MD)
218 if !ok {
219 return nil
220 }
221
222 if v, ok := md[key]; ok {
223 return copyOf(v)
224 }
225 for k, v := range md {
226 // Case insensitive comparison: MD is a map, and there's no guarantee
227 // that the MD attached to the context is created using our helper
228 // functions.
229 if strings.EqualFold(k, key) {
230 return copyOf(v)
231 }
232 }
233 return nil
234}
235
236func copyOf(v []string) []string {
237 vals := make([]string, len(v))

Callers 8

TagsFunction · 0.92
TraceFunction · 0.92
statsTagRPCMethod · 0.92
traceTagRPCMethod · 0.92
GetMethod · 0.92

Calls 2

copyOfFunction · 0.85
ValueMethod · 0.45