Fix Auth Headers (#1324)

Co-authored-by: Ben Toogood <ben@micro.mu>
This commit is contained in:
ben-toogood 2020-03-10 16:47:01 +00:00 committed by Vasiliy Tolstov
parent d0c0366e0c
commit 4f5a19bf30

View File

@ -123,7 +123,7 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R
if md, ok := metadata.FromContext(ctx); ok { if md, ok := metadata.FromContext(ctx); ok {
header = make(map[string]string, len(md)) header = make(map[string]string, len(md))
for k, v := range md { for k, v := range md {
header[k] = v header[strings.ToLower(k)] = v
} }
} else { } else {
header = make(map[string]string) header = make(map[string]string)
@ -133,9 +133,12 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R
header["timeout"] = fmt.Sprintf("%d", opts.RequestTimeout) header["timeout"] = fmt.Sprintf("%d", opts.RequestTimeout)
// set the content type for the request // set the content type for the request
header["x-content-type"] = req.ContentType() header["x-content-type"] = req.ContentType()
// set the authorization token if one is saved locally // set the authorization token if one is saved locally
if token, err := config.Get("token"); err == nil && len(token) > 0 { if len(header["authorization"]) == 0 {
header["authorization"] = BearerScheme + token if token, err := config.Get("token"); err == nil && len(token) > 0 {
header["authorization"] = BearerScheme + token
}
} }
md := gmetadata.New(header) md := gmetadata.New(header)