Merge pull request #132 from micro/ctx
Make copy of metadata in setHeaders
This commit is contained in:
commit
2c65a38ba9
12
wrapper.go
12
wrapper.go
@ -13,15 +13,21 @@ type clientWrapper struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *clientWrapper) setHeaders(ctx context.Context) context.Context {
|
func (c *clientWrapper) setHeaders(ctx context.Context) context.Context {
|
||||||
md, ok := metadata.FromContext(ctx)
|
md := make(metadata.Metadata)
|
||||||
if !ok {
|
|
||||||
md = 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 {
|
for k, v := range c.headers {
|
||||||
if _, ok := md[k]; !ok {
|
if _, ok := md[k]; !ok {
|
||||||
md[k] = v
|
md[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return metadata.NewContext(ctx, md)
|
return metadata.NewContext(ctx, md)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +38,7 @@ func TestWrapper(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx := metadata.NewContext(context.Background(), d.existing)
|
ctx := metadata.NewContext(context.Background(), d.existing)
|
||||||
c.setHeaders(ctx)
|
ctx = c.setHeaders(ctx)
|
||||||
|
|
||||||
md, _ := metadata.FromContext(ctx)
|
md, _ := metadata.FromContext(ctx)
|
||||||
|
|
||||||
for k, v := range d.headers {
|
for k, v := range d.headers {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user