metadata: fix for grpc case
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
b6a0e4d983
commit
275b0a64e5
@ -4,6 +4,7 @@ package metadata
|
|||||||
import (
|
import (
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -73,6 +74,9 @@ func (md Metadata) Get(key string) (string, bool) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
// slow path
|
// slow path
|
||||||
val, ok = md[textproto.CanonicalMIMEHeaderKey(key)]
|
val, ok = md[textproto.CanonicalMIMEHeaderKey(key)]
|
||||||
|
if !ok {
|
||||||
|
val, ok = md[strings.ToLower(key)]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return val, ok
|
return val, ok
|
||||||
}
|
}
|
||||||
@ -94,6 +98,8 @@ func (md Metadata) Del(keys ...string) {
|
|||||||
delete(md, key)
|
delete(md, key)
|
||||||
// slow path
|
// slow path
|
||||||
delete(md, textproto.CanonicalMIMEHeaderKey(key))
|
delete(md, textproto.CanonicalMIMEHeaderKey(key))
|
||||||
|
// very slow path
|
||||||
|
delete(md, strings.ToLower(key))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,15 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestLowercase(t *testing.T) {
|
||||||
|
md := New(1)
|
||||||
|
md["x-request-id"] = "12345"
|
||||||
|
v, ok := md.Get("X-Request-Id")
|
||||||
|
if !ok || v == "" {
|
||||||
|
t.Fatalf("metadata invalid %#+v", md)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestMultipleUsage(t *testing.T) {
|
func TestMultipleUsage(t *testing.T) {
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
md := New(0)
|
md := New(0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user