MCPcopy
hub / github.com/irbis-sh/zen-desktop / Parse

Method Parse

internal/networkrules/rulemodifiers/domain.go:29–54  ·  view source on GitHub ↗
(modifier string)

Source from the content-addressed store, hash-verified

27var _ ConditionModifier = (*DomainModifier)(nil)
28
29func (m *DomainModifier) Parse(modifier string) error {
30 eqIndex := strings.IndexByte(modifier, '=')
31 if eqIndex == -1 || eqIndex == len(modifier)-1 {
32 return errors.New("invalid domain modifier")
33 }
34 value := modifier[eqIndex+1:]
35
36 m.inverted = strings.HasPrefix(value, "~")
37 matches := domainModifierRegex.FindAllString(value, -1)
38 m.entries = make([]domainModifierEntry, len(matches))
39 for i, entry := range matches {
40 inverted := len(entry) > 0 && entry[0] == '~'
41 if inverted != m.inverted {
42 return errors.New("cannot mix inverted and non-inverted method modifiers")
43 }
44 if inverted {
45 entry = entry[1:]
46 }
47
48 m.entries[i] = domainModifierEntry{}
49 if err := m.entries[i].Parse(entry); err != nil {
50 return fmt.Errorf("parse entry %q: %w", entry, err)
51 }
52 }
53 return nil
54}
55
56func (m *DomainModifier) ShouldMatchReq(req *http.Request) bool {
57 var hostname string

Callers 2

TestDomainModifierFunction · 0.95
newDomainModifierFunction · 0.95

Calls 1

ParseMethod · 0.65

Tested by 2

TestDomainModifierFunction · 0.76
newDomainModifierFunction · 0.76