FromIncomingContext returns the incoming metadata in ctx if it exists. All keys in the returned MD are lowercase.
(ctx context.Context)
| 195 | // |
| 196 | // All keys in the returned MD are lowercase. |
| 197 | func FromIncomingContext(ctx context.Context) (MD, bool) { |
| 198 | md, ok := ctx.Value(mdIncomingKey{}).(MD) |
| 199 | if !ok { |
| 200 | return nil, false |
| 201 | } |
| 202 | out := make(MD, len(md)) |
| 203 | for k, v := range md { |
| 204 | // We need to manually convert all keys to lower case, because MD is a |
| 205 | // map, and there's no guarantee that the MD attached to the context is |
| 206 | // created using our helper functions. |
| 207 | key := strings.ToLower(k) |
| 208 | out[key] = copyOf(v) |
| 209 | } |
| 210 | return out, true |
| 211 | } |
| 212 | |
| 213 | // ValueFromIncomingContext returns the metadata value corresponding to the metadata |
| 214 | // key from the incoming metadata if it exists. Keys are matched in a case insensitive |