feat: add domain rule configuration

This commit is contained in:
putyy
2025-12-26 17:19:36 +08:00
committed by putyy
parent 86378b9fba
commit 983d72d65a

View File

@@ -9,9 +9,8 @@ import (
type Rule struct {
raw string
isNeg bool // 是否否定规则(以 ! 开头)
isWildcard bool // 是否为 *.domain 形式
isAll bool
isNeg bool // 是否否定规则(以 ! 开头)
isWildcard bool // 是否为 *.domain 形式
domain string // 域名部分,不含 "*."
}
@@ -52,15 +51,6 @@ func (r *RuleSet) Load(rs string) error {
}
}
if line == "*" {
rules = append(rules, Rule{
raw: "*",
isAll: true,
isNeg: isNeg,
})
continue
}
isWildcard := false
domain := line
if strings.HasPrefix(line, "*.") {
@@ -106,20 +96,22 @@ func (r *RuleSet) shouldMitm(host string) bool {
action := false
for _, rule := range r.rules {
if rule.isAll {
action = !rule.isNeg
continue
}
if rule.isWildcard {
if h == rule.domain || strings.HasSuffix(h, "."+rule.domain) {
action = !rule.isNeg
if rule.isNeg {
action = false
} else {
action = true
}
}
} else {
if h == rule.domain {
if rule.isNeg {
action = false
} else {
action = true
}
}
continue
}
if h == rule.domain {
action = !rule.isNeg
}
}
return action