Make copy of metadata in setHeaders

This commit is contained in:
Asim 2016-11-02 17:21:53 +00:00
parent a36e042983
commit 7635bd9753
2 changed files with 10 additions and 5 deletions

View File

@ -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)
}

View File

@ -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 {