From d0eb4fd34cfc7ac4520bf83cb564e10a74931811 Mon Sep 17 00:00:00 2001 From: pujielan <524086595@qq.com> Date: Mon, 15 Jan 2018 18:30:43 +0800 Subject: [PATCH] [REV] Update lds header setting support --- pkg/node/api/model/discover.go | 3 ++- pkg/node/core/service/discover_server.go | 28 +++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/pkg/node/api/model/discover.go b/pkg/node/api/model/discover.go index 8e90da643..6b3f077d8 100644 --- a/pkg/node/api/model/discover.go +++ b/pkg/node/api/model/discover.go @@ -135,7 +135,8 @@ type PieceHTTPRoutes struct { TimeoutMS int `json:"timeout_ms"` Prefix string `json:"prefix"` Cluster string `json:"cluster"` - //Headers []*PieceHeader `json:"headers"` + //Headers []PieceHeader `json:"headers"` + Headers interface{} `json:"headers"` } //PieceHeader PieceHeader diff --git a/pkg/node/core/service/discover_server.go b/pkg/node/core/service/discover_server.go index 050efc753..7abef87f7 100644 --- a/pkg/node/core/service/discover_server.go +++ b/pkg/node/core/service/discover_server.go @@ -279,12 +279,19 @@ func (d *DiscoverAction) DiscoverListeners( } } } + headers := d.ToolsGetRouterItem( + destServiceAlias, + node_model.HEADERS, options) + if headers == nil { + mm := make(map[string]string) + mm["name"] = "with_empty_header" + headers = []map[string]string{mm} + } prs := &node_model.PieceHTTPRoutes{ TimeoutMS: 0, Prefix: d.ToolsGetRouterItem(destServiceAlias, node_model.PREFIX, options).(string), Cluster: fmt.Sprintf("%s_%s_%s_%d", namespace, serviceAlias, destServiceAlias, port), - //Headers: d.ToolsGetRouterItem(destServiceAlias, - // node_model.HEADERS, &sr).([]*node_model.PieceHeader), + Headers: headers, } pvh := &node_model.PieceHTTPVirtualHost{ Name: fmt.Sprintf("%s_%s_%s_%d", namespace, serviceAlias, destServiceAlias, port), @@ -558,7 +565,22 @@ func (d *DiscoverAction) ToolsGetRouterItem( } return 3 case node_model.HEADERS: - return "" + if headers, ok := sr[node_model.HEADERS]; ok { + var np []node_model.PieceHeader + parents := strings.Split(headers.(string), ";") + for _, h := range parents { + headers := strings.Split(h, ":") + if len(headers) == 2 { + ph := node_model.PieceHeader{ + Name: headers[0], + Value: headers[1], + } + np = append(np, ph) + } + } + return np + } + return nil case node_model.DOMAINS: if domain, ok := sr[node_model.DOMAINS]; ok { if destAlias != "" {