From e204f3e2e802ac34161643e3606128740b44e436 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 26 Mar 2020 18:50:00 +0000 Subject: [PATCH] Add metadata Get method (#1425) --- metadata/metadata.go | 12 ++++++++++++ proxy/mucp/mucp.go | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/metadata/metadata.go b/metadata/metadata.go index c41aa284..63402fa9 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -13,6 +13,18 @@ type metaKey struct{} // from Transport headers. type Metadata map[string]string +func (md Metadata) Get(key string) (string, bool) { + // attempt to get as is + val, ok := md[key] + if ok { + return val, ok + } + + // attempt to get lower case + val, ok = md[strings.Title(key)] + return val, ok +} + // Copy makes a copy of the metadata func Copy(md Metadata) Metadata { cmd := make(Metadata) diff --git a/proxy/mucp/mucp.go b/proxy/mucp/mucp.go index 4b8a1926..da901c13 100644 --- a/proxy/mucp/mucp.go +++ b/proxy/mucp/mucp.go @@ -120,7 +120,7 @@ func (p *Proxy) filterRoutes(ctx context.Context, routes []router.Route) []route // filter the routes based on our headers for _, route := range routes { // process only routes for this id - if id := md["Micro-Router"]; len(id) > 0 { + if id, ok := md.Get("Micro-Router"); ok && len(id) > 0 { if route.Router != id { // skip routes that don't mwatch continue @@ -128,7 +128,7 @@ func (p *Proxy) filterRoutes(ctx context.Context, routes []router.Route) []route } // only process routes with this network - if net := md["Micro-Network"]; len(net) > 0 { + if net, ok := md.Get("Micro-Network"); ok && len(net) > 0 { if route.Network != net { // skip routes that don't mwatch continue @@ -136,7 +136,7 @@ func (p *Proxy) filterRoutes(ctx context.Context, routes []router.Route) []route } // process only this gateway - if gw := md["Micro-Gateway"]; len(gw) > 0 { + if gw, ok := md.Get("Micro-Gateway"); ok && len(gw) > 0 { // if the gateway matches our address // special case, take the routes with no gateway // TODO: should we strip the gateway from the context?