From e5ddd92677ee2e6da7738be8755e31530bae61af Mon Sep 17 00:00:00 2001 From: Emile Vauge Date: Thu, 7 Apr 2016 15:01:04 +0200 Subject: [PATCH] Fix port support in host rule Signed-off-by: Emile Vauge --- rules.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rules.go b/rules.go index 29152008a..23668725d 100644 --- a/rules.go +++ b/rules.go @@ -3,6 +3,7 @@ package main import ( "errors" "github.com/gorilla/mux" + "net" "net/http" "reflect" "sort" @@ -12,12 +13,17 @@ import ( // Rules holds rule parsing and configuration type Rules struct { route *serverRoute + err error } func (r *Rules) host(hosts ...string) *mux.Route { return r.route.route.MatcherFunc(func(req *http.Request, route *mux.RouteMatch) bool { + reqHost, _, err := net.SplitHostPort(req.Host) + if err != nil { + reqHost = req.Host + } for _, host := range hosts { - if strings.EqualFold(req.Host, strings.TrimSpace(host)) { + if reqHost == strings.TrimSpace(host) { return true } } @@ -129,6 +135,9 @@ func (r *Rules) Parse(expression string) (*mux.Route, error) { method := reflect.ValueOf(parsedFunction) if method.IsValid() { resultRoute := method.Call(inputs)[0].Interface().(*mux.Route) + if r.err != nil { + return nil, r.err + } if resultRoute.GetError() != nil { return nil, resultRoute.GetError() }