add wildcard supports for vhost

This commit is contained in:
ginuerzh
2022-11-12 13:43:43 +08:00
parent 1ff2bab1f0
commit f87183b652
3 changed files with 18 additions and 16 deletions

View File

@ -3,6 +3,7 @@ package chain
import (
"context"
"net"
"strings"
"github.com/go-gost/core/bypass"
"github.com/go-gost/core/chain"
@ -88,13 +89,15 @@ func (p *chainHop) Select(ctx context.Context, opts ...chain.SelectOption) *chai
if node == nil {
continue
}
if node.Options().Host == "" {
vhost := node.Options().Host
if vhost == "" {
nodes = append(nodes, node)
continue
}
if node.Options().Host == host {
if vhost == host ||
vhost[0] == '.' && strings.HasSuffix(host, vhost[1:]) {
filters = append(filters, node)
p.options.logger.Debugf("find node for host: %s", host)
p.options.logger.Debugf("find node for host: %s(match %s)", host, vhost)
}
}
if len(filters) == 0 {