Fix port support in host rule

Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
Emile Vauge 2016-04-07 15:01:04 +02:00
parent 04628056af
commit e5ddd92677
No known key found for this signature in database
GPG key ID: D808B4C167352E59

View file

@ -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()
}