fix metadata issues with uppercase letters

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2020-09-30 16:14:54 +03:00
parent efd9075d9b
commit 9c55b1d06a
3 changed files with 43 additions and 64 deletions

View File

@@ -3,7 +3,6 @@ package ctx
import (
"context"
"net/http"
"net/textproto"
"strings"
"github.com/unistack-org/micro/v3/metadata"
@@ -13,10 +12,11 @@ func FromRequest(r *http.Request) context.Context {
ctx := r.Context()
md, ok := metadata.FromContext(ctx)
if !ok {
md = make(metadata.Metadata)
// create needed map with specific len
md = make(metadata.Metadata, len(r.Header)+2)
}
for k, v := range r.Header {
md[textproto.CanonicalMIMEHeaderKey(k)] = strings.Join(v, ",")
for key, val := range r.Header {
md.Set(key, strings.Join(val, ","))
}
// pass http host
md["Host"] = r.Host