Skip to content

Commit

Permalink
Issue #389: match exact host before glob matches
Browse files Browse the repository at this point in the history
  • Loading branch information
magiconair committed Nov 15, 2017
1 parent 4dbab1b commit 8ba2729
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions route/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (t Table) matchingHosts(req *http.Request) (hosts []string) {
hosts = append(hosts, pattern)
}
}
sort.Strings(hosts)
sort.Reverse(sort.StringSlice(hosts))
return hosts
}

Expand Down Expand Up @@ -364,7 +364,7 @@ func (t Table) config(addWeight bool) []string {
hosts = append(hosts, host)
}
}
sort.Strings(hosts)
sort.Reverse(sort.StringSlice(hosts))

// entries without host come last
hosts = append(hosts, "")
Expand Down
4 changes: 4 additions & 0 deletions route/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ func TestTableLookup(t *testing.T) {
route add svc abc.com/foo/ http://foo.com:2000
route add svc abc.com/foo/bar http://foo.com:2500
route add svc abc.com/foo/bar/ http://foo.com:3000
route add svc def.abc.com/foo/ http://foo.com:3100
route add svc *.abc.com/ http://foo.com:4000
route add svc *.abc.com/foo/ http://foo.com:5000
`
Expand Down Expand Up @@ -513,6 +514,9 @@ func TestTableLookup(t *testing.T) {
{&http.Request{Host: "x.y.abc.com", URL: mustParse("/foo/")}, "http://foo.com:5000"},
{&http.Request{Host: "y.abc.com:80", URL: mustParse("/foo/")}, "http://foo.com:5000"},
{&http.Request{Host: "y.abc.com:443", URL: mustParse("/foo/"), TLS: &tls.ConnectionState{}}, "http://foo.com:5000"},

// exact match has precedence over glob match
{&http.Request{Host: "def.abc.com", URL: mustParse("/foo/")}, "http://foo.com:3100"},
}

for i, tt := range tests {
Expand Down

0 comments on commit 8ba2729

Please sign in to comment.