Add regex support for domainsExcluded (#3449)

* Add regx support for domainsExcluded

* format
This commit is contained in:
风扇滑翔翼 2024-06-16 22:51:52 +08:00 committed by GitHub
parent 219a7dac20
commit ae97821e40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,6 +4,7 @@ package dispatcher
import (
"context"
"regexp"
"strings"
"sync"
"time"
@ -186,10 +187,22 @@ func (d *DefaultDispatcher) shouldOverride(ctx context.Context, result SniffResu
return false
}
for _, d := range request.ExcludeForDomain {
if strings.HasPrefix(d, "regexp:") {
pattern := d[7:]
re, err := regexp.Compile(pattern)
if err != nil {
newError("Unable to compile regex").WriteToLog(session.ExportIDToError(ctx))
continue
}
if re.MatchString(domain) {
return false
}
} else {
if strings.ToLower(domain) == d {
return false
}
}
}
protocolString := result.Protocol()
if resComp, ok := result.(SnifferResultComposite); ok {
protocolString = resComp.ProtocolForDomainResult()