From 7635bd9753a43a5252d3d7834f53efcfd28049df Mon Sep 17 00:00:00 2001 From: Asim Date: Wed, 2 Nov 2016 17:21:53 +0000 Subject: [PATCH] Make copy of metadata in setHeaders --- wrapper.go | 12 +++++++++--- wrapper_test.go | 3 +-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/wrapper.go b/wrapper.go index a3bac9af..11babf24 100644 --- a/wrapper.go +++ b/wrapper.go @@ -13,15 +13,21 @@ type clientWrapper struct { } func (c *clientWrapper) setHeaders(ctx context.Context) context.Context { - md, ok := metadata.FromContext(ctx) - if !ok { - md = metadata.Metadata{} + md := make(metadata.Metadata) + + if mda, ok := metadata.FromContext(ctx); ok { + // make copy of metadata + for k, v := range mda { + md[k] = v + } } + for k, v := range c.headers { if _, ok := md[k]; !ok { md[k] = v } } + return metadata.NewContext(ctx, md) } diff --git a/wrapper_test.go b/wrapper_test.go index 439ed10d..f22173c1 100644 --- a/wrapper_test.go +++ b/wrapper_test.go @@ -38,8 +38,7 @@ func TestWrapper(t *testing.T) { } ctx := metadata.NewContext(context.Background(), d.existing) - c.setHeaders(ctx) - + ctx = c.setHeaders(ctx) md, _ := metadata.FromContext(ctx) for k, v := range d.headers {