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

Method Parse

internal/networkrules/rulemodifiers/method.go:17–43  ·  view source on GitHub ↗
(modifier string)

Source from the content-addressed store, hash-verified

15var _ ConditionModifier = (*MethodModifier)(nil)
16
17func (m *MethodModifier) Parse(modifier string) error {
18 eqIndex := strings.IndexByte(modifier, '=')
19 if eqIndex == -1 {
20 return fmt.Errorf("invalid method modifier")
21 }
22 value := modifier[eqIndex+1:]
23
24 m.inverted = strings.HasPrefix(value, "~")
25 entries := strings.Split(value, "|")
26 m.entries = make([]methodModifierEntry, len(entries))
27 for i, entry := range entries {
28 if entry == "" {
29 return errors.New("empty method modifier entry")
30 }
31 inverted := strings.HasPrefix(entry, "~")
32 if inverted != m.inverted {
33 return errors.New("cannot mix inverted and non-inverted method modifiers")
34 }
35 if inverted {
36 entry = entry[1:]
37 }
38
39 m.entries[i] = methodModifierEntry{}
40 m.entries[i].Parse(entry)
41 }
42 return nil
43}
44
45func (m *MethodModifier) ShouldMatchReq(req *http.Request) bool {
46 matches := false

Callers 1

TestMethodModifierFunction · 0.95

Calls 1

ParseMethod · 0.65

Tested by 1

TestMethodModifierFunction · 0.76