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

Function FromOutgoingContext

metadata/metadata.go:260–290  ·  view source on GitHub ↗

FromOutgoingContext returns the outgoing metadata in ctx if it exists. All keys in the returned MD are lowercase.

(ctx context.Context)

Source from the content-addressed store, hash-verified

258//
259// All keys in the returned MD are lowercase.
260func FromOutgoingContext(ctx context.Context) (MD, bool) {
261 raw, ok := ctx.Value(mdOutgoingKey{}).(rawMD)
262 if !ok {
263 return nil, false
264 }
265
266 mdSize := len(raw.md)
267 for i := range raw.added {
268 mdSize += len(raw.added[i]) / 2
269 }
270
271 out := make(MD, mdSize)
272 for k, v := range raw.md {
273 // We need to manually convert all keys to lower case, because MD is a
274 // map, and there's no guarantee that the MD attached to the context is
275 // created using our helper functions.
276 key := strings.ToLower(k)
277 out[key] = copyOf(v)
278 }
279 for _, added := range raw.added {
280 if len(added)%2 == 1 {
281 panic(fmt.Sprintf("metadata: FromOutgoingContext got an odd number of input pairs for metadata: %d", len(added)))
282 }
283
284 for i := 0; i < len(added); i += 2 {
285 key := strings.ToLower(added[i])
286 out[key] = append(out[key], added[i+1])
287 }
288 }
289 return out, ok
290}
291
292type rawMD struct {
293 md MD

Callers 15

newStreamMethod · 0.92
PickMethod · 0.92
PickMethod · 0.92
TestConfigSelectorMethod · 0.92
NewStreamMethod · 0.92
generateHashMethod · 0.92
MatchMethod · 0.92
injectDelayFunction · 0.92
injectAbortFunction · 0.92
getOutgoingStatsFunction · 0.92

Calls 2

copyOfFunction · 0.85
ValueMethod · 0.45