diff --git a/metadata/metadata.go b/metadata/metadata.go index 7fd26e8a..46744b9a 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -4,6 +4,7 @@ package metadata import ( "net/textproto" "sort" + "strings" ) var ( @@ -73,6 +74,9 @@ func (md Metadata) Get(key string) (string, bool) { if !ok { // slow path val, ok = md[textproto.CanonicalMIMEHeaderKey(key)] + if !ok { + val, ok = md[strings.ToLower(key)] + } } return val, ok } @@ -94,6 +98,8 @@ func (md Metadata) Del(keys ...string) { delete(md, key) // slow path delete(md, textproto.CanonicalMIMEHeaderKey(key)) + // very slow path + delete(md, strings.ToLower(key)) } } diff --git a/metadata/metadata_test.go b/metadata/metadata_test.go index 84738f81..5c45a133 100644 --- a/metadata/metadata_test.go +++ b/metadata/metadata_test.go @@ -5,6 +5,15 @@ import ( "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) { ctx := context.TODO() md := New(0)