diff --git a/Gopkg.lock b/Gopkg.lock index e8b4586ec..6400ac3a2 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -291,7 +291,7 @@ branch = "master" name = "github.com/containous/mux" packages = ["."] - revision = "06ccd3e75091eb659b1d720cda0e16bc7057954c" + revision = "c33f32e268983f989290677351b871b65da75ba5" [[projects]] name = "github.com/containous/staert" @@ -819,6 +819,7 @@ revision = "9b66602d496a139e4722bdde32f0f1ac1c12d4a8" [[projects]] + branch = "master" name = "github.com/jjcollinge/servicefabric" packages = ["."] revision = "8eebe170fa1ba25d3dfb928b3f86a7313b13b9fe" diff --git a/rules/rules.go b/rules/rules.go index 44332261b..b523a882f 100644 --- a/rules/rules.go +++ b/rules/rules.go @@ -53,10 +53,10 @@ func (r *Rules) host(hosts ...string) *mux.Route { }) } -func (r *Rules) hostRegexp(hosts ...string) *mux.Route { +func (r *Rules) hostRegexp(hostPatterns ...string) *mux.Route { router := r.Route.Route.Subrouter() - for _, host := range hosts { - router.Host(strings.ToLower(host)) + for _, hostPattern := range hostPatterns { + router.Host(hostPattern) } return r.Route.Route } diff --git a/rules/rules_test.go b/rules/rules_test.go index 7239ad750..a843e63ee 100644 --- a/rules/rules_test.go +++ b/rules/rules_test.go @@ -195,6 +195,39 @@ func TestHostRegexp(t *testing.T) { "http://barcom": false, }, }, + { + desc: "regex insensitive", + hostExp: "{dummy:[A-Za-z-]+\\.bar\\.com}", + urls: map[string]bool{ + "http://FOO.bar.com": true, + "http://foo.bar.com": true, + "http://fooubar.com": false, + "http://barucom": false, + "http://barcom": false, + }, + }, + { + desc: "insensitive host", + hostExp: "{dummy:[a-z-]+\\.bar\\.com}", + urls: map[string]bool{ + "http://FOO.bar.com": true, + "http://foo.bar.com": true, + "http://fooubar.com": false, + "http://barucom": false, + "http://barcom": false, + }, + }, + { + desc: "insensitive host simple", + hostExp: "foo.bar.com", + urls: map[string]bool{ + "http://FOO.bar.com": true, + "http://foo.bar.com": true, + "http://fooubar.com": false, + "http://barucom": false, + "http://barcom": false, + }, + }, } for _, test := range testCases { @@ -212,7 +245,7 @@ func TestHostRegexp(t *testing.T) { for testURL, match := range test.urls { req := testhelpers.MustNewRequest(http.MethodGet, testURL, nil) - assert.Equal(t, match, rt.Match(req, &mux.RouteMatch{})) + assert.Equal(t, match, rt.Match(req, &mux.RouteMatch{}), testURL) } }) } diff --git a/vendor/github.com/containous/mux/regexp.go b/vendor/github.com/containous/mux/regexp.go index da8114ca4..d3049b7df 100644 --- a/vendor/github.com/containous/mux/regexp.go +++ b/vendor/github.com/containous/mux/regexp.go @@ -53,6 +53,12 @@ func newRouteRegexp(tpl string, matchHost, matchPrefix, matchQuery, strictSlash, varsN := make([]string, len(idxs)/2) varsR := make([]*regexp.Regexp, len(idxs)/2) pattern := bytes.NewBufferString("") + + // Host matching is case insensitive + if matchHost { + fmt.Fprint(pattern, "(?i)") + } + pattern.WriteByte('^') reverse := bytes.NewBufferString("") var end int