Merge branch 'v1.6' into v1.7
This commit is contained in:
commit
538424b01c
4 changed files with 49 additions and 14 deletions
|
@ -8,7 +8,6 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/BurntSushi/ty/fun"
|
||||
"github.com/containous/mux"
|
||||
"github.com/containous/traefik/hostresolver"
|
||||
"github.com/containous/traefik/log"
|
||||
|
@ -288,9 +287,11 @@ func (r *Rules) Parse(expression string) (*mux.Route, error) {
|
|||
// ParseDomains parses rules expressions and returns domains
|
||||
func (r *Rules) ParseDomains(expression string) ([]string, error) {
|
||||
var domains []string
|
||||
isHostRule := false
|
||||
|
||||
err := r.parseRules(expression, func(functionName string, function interface{}, arguments []string) error {
|
||||
if functionName == "Host" {
|
||||
isHostRule = true
|
||||
domains = append(domains, arguments...)
|
||||
}
|
||||
return nil
|
||||
|
@ -299,5 +300,18 @@ func (r *Rules) ParseDomains(expression string) ([]string, error) {
|
|||
return nil, fmt.Errorf("error parsing domains: %v", err)
|
||||
}
|
||||
|
||||
return fun.Map(strings.ToLower, domains).([]string), nil
|
||||
var cleanDomains []string
|
||||
for _, domain := range domains {
|
||||
canonicalDomain := strings.ToLower(domain)
|
||||
if len(canonicalDomain) > 0 {
|
||||
cleanDomains = append(cleanDomains, canonicalDomain)
|
||||
}
|
||||
}
|
||||
|
||||
// Return an error if an Host rule is detected but no domain are parsed
|
||||
if isHostRule && len(cleanDomains) == 0 {
|
||||
return nil, fmt.Errorf("unable to parse correctly the domains in the Host rule from %q", expression)
|
||||
}
|
||||
|
||||
return cleanDomains, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue