func (m MatchHost) Match(r *http.Request) bool {
	reqHost, _, err := net.SplitHostPort(r.Host)
	if err != nil {
		// OK; probably didn't have a port
		reqHost = r.Host

		// make sure we strip the brackets from IPv6 addresses
		reqHost = strings.TrimPrefix(reqHost, "[")
		reqHost = strings.TrimSuffix(reqHost, "]")
	}

	if m.large() {
		// fast path: locate exact match using binary search (about 100-1000x faster for large lists)
		pos := sort.Search(len(m), func(i int) bool {
			if m.fuzzy(m[i]) {
				return false
			}
			return m[i] >= reqHost
		})
		if pos < len(m) && m[pos] == reqHost {
			return true
		}
	}

	repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)

outer:
	for _, host := range m {
		// fast path: if matcher is large, we already know we don't have an exact
		// match, so we're only looking for fuzzy match now, which should be at the
		// front of the list; if we have reached a value that is not fuzzy, there
		// will be no match and we can short-circuit for efficiency
		if m.large() && !m.fuzzy(host) {
			break
		}

		host = repl.ReplaceAll(host, "")
		if strings.Contains(host, "*") {
			patternParts := strings.Split(host, ".")
			incomingParts := strings.Split(reqHost, ".")
			if len(patternParts) != len(incomingParts) {
				continue
			}
			for i := range patternParts {
				if patternParts[i] == "*" {
					continue
				}
				if !strings.EqualFold(patternParts[i], incomingParts[i]) {
					continue outer
				}
			}
			return true
		} else if strings.EqualFold(reqHost, host) {
			return true
		}
	}

	return false
}
// Match returns true if r matches m.
Match returns true if r matches m.
// Match returns true if r matches m .
func (m MatchHost) Match(r *http.Request) bool {
	reqHost, _, err := net.SplitHostPort(r.Host)
	if err != nil {
		reqHost = r.Host
		reqHost = strings.TrimPrefix(reqHost, "[")
		reqHost = strings.TrimSuffix(reqHost, "]")
	}
	if m.large() {
		pos := sort.Search(len(m), func(i int) bool {
			if m.fuzzy(m[i]) {
				return false
			}
			return m[i] >= reqHost
		})
		if pos < len(m) && m[pos] == reqHost {
			return true
		}
	}
	repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
outer:
	for _, host := range m {
		if m.large() && !m.fuzzy(host) {
			break
		}
		host = repl.ReplaceAll(host, "")
		if strings.Contains(host, "*") {
			patternParts := strings.Split(host, ".")
			incomingParts := strings.Split(reqHost, ".")
			if len(patternParts) != len(incomingParts) {
				continue
			}
			for i := range patternParts {
				if patternParts[i] == "*" {
					continue
				}
				if !strings.EqualFold(patternParts[i], incomingParts[i]) {
					continue outer
				}
			}
			return true
		} else if strings.EqualFold(reqHost, host) {
			return true
		}
	}
	return false
}
func ( m MatchHost ) Match ( r * http . Request ) bool { reqHost , _ , err := net . SplitHostPort ( r . Host ) if err != nil { reqHost = r . Host reqHost = strings . TrimPrefix ( reqHost , " " ) reqHost = strings . TrimSuffix ( reqHost , " " ) } if m . large ( ) { pos := sort . Search ( len ( m ) , func ( i int ) bool { if m . fuzzy ( m [ i ] ) { return false } return m [ i ] >= reqHost } ) if pos < len ( m ) && m [ pos ] == reqHost { return true } } repl := r . Context ( ) . Value ( caddy . ReplacerCtxKey ) . ( * caddy . Replacer ) outer : for _ , host := range m { if m . large ( ) && ! m . fuzzy ( host ) { break } host = repl . ReplaceAll ( host , " " ) if strings . Contains ( host , " " ) { patternParts := strings . Split ( host , " " ) incomingParts := strings . Split ( reqHost , " " ) if len ( patternParts ) != len ( incomingParts ) { continue } for i := range patternParts { if patternParts [ i ] == " " { continue } if ! strings . EqualFold ( patternParts [ i ] , incomingParts [ i ] ) { continue outer } } return true } else if strings . EqualFold ( reqHost , host ) { return true } } return false }
Match returns true if r matches m.
Match returns true if r matches m .
// OK; probably didn't have a port // make sure we strip the brackets from IPv6 addresses // fast path: locate exact match using binary search (about 100-1000x faster for large lists) // fast path: if matcher is large, we already know we don't have an exact // match, so we're only looking for fuzzy match now, which should be at the // front of the list; if we have reached a value that is not fuzzy, there // will be no match and we can short-circuit for efficiency