Skip to content

Commit

Permalink
Changed to string array
Browse files Browse the repository at this point in the history
  • Loading branch information
lonelycode authored and buger committed Oct 23, 2017
1 parent 8f911e7 commit 46cdc47
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
8 changes: 4 additions & 4 deletions analytics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ func TestTagHeaders(t *testing.T) {
req.Header.Set("X-Ignore-Me", "4")

existingTags := []string{"first", "second"}
existingTags = tagHeaders(req, map[string]interface{}{
"x-tag-me": 0,
"x-tag-me2": 0,
"x-tag-me3": 0},
existingTags = tagHeaders(req, []string{
"x-tag-me",
"x-tag-me2",
"x-tag-me3"},
existingTags)

if len(existingTags) == 2 {
Expand Down
7 changes: 4 additions & 3 deletions api_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ func processSpec(spec *APISpec, apisByListen map[string]int,

if len(spec.TagHeaders) > 0 {
// Ensure all headers marked for tagging are lowercase
lowerCaseHeaders := make(map[string]interface{})
for k, v := range spec.TagHeaders {
lowerCaseHeaders[strings.ToLower(k)] = v
lowerCaseHeaders := make([]string, len(spec.TagHeaders))
for i, k := range spec.TagHeaders {
lowerCaseHeaders[i] = strings.ToLower(k)

}
spec.TagHeaders = lowerCaseHeaders
}
Expand Down
2 changes: 1 addition & 1 deletion apidef/api_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ type APIDefinition struct {
Tags []string `bson:"tags" json:"tags"`
EnableContextVars bool `bson:"enable_context_vars" json:"enable_context_vars"`
ConfigData map[string]interface{} `bson:"config_data" json:"config_data"`
TagHeaders map[string]interface{} `bson:"tag_headers" json:"tag_headers"`
TagHeaders []string `bson:"tag_headers" json:"tag_headers"`
GlobalRateLimit GlobalRateLimit `bson:"global_rate_limit" json:"global_rate_limit"`
}

Expand Down
11 changes: 9 additions & 2 deletions handler_success.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,17 @@ type SuccessHandler struct {
BaseMiddleware
}

func tagHeaders(r *http.Request, th map[string]interface{}, tags []string) []string {
func tagHeaders(r *http.Request, th []string, tags []string) []string {
for k, v := range r.Header {
cleanK := strings.ToLower(k)
_, ok := th[cleanK]
ok := false
for _, hname := range th {
if hname == cleanK {
ok = true
break
}
}

if ok {
for _, val := range v {
tagName := fmt.Sprintf("%s-%s", cleanK, val)
Expand Down

0 comments on commit 46cdc47

Please sign in to comment.