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

Method ModifyRes

internal/networkrules/networkrules.go:86–121  ·  view source on GitHub ↗
(req *http.Request, res *http.Response)

Source from the content-addressed store, hash-verified

84}
85
86func (nr *NetworkRules) ModifyRes(req *http.Request, res *http.Response) ([]rule.Rule, error) {
87 url := renderURLWithoutPort(req.URL)
88
89 primaryRules := nr.primaryStore.Get(url)
90 primaryRules = filter(primaryRules, func(r *rule.Rule) bool {
91 return r.ShouldMatchRes(res)
92 })
93 if len(primaryRules) == 0 {
94 return nil, nil
95 }
96
97 exceptions := nr.exceptionStore.Get(url)
98 exceptions = filter(exceptions, func(er *exceptionrule.ExceptionRule) bool {
99 return er.ShouldMatchRes(res)
100 })
101
102 var appliedRules []rule.Rule
103outer:
104 for _, r := range primaryRules {
105 for _, ex := range exceptions {
106 if ex.Cancels(r) {
107 continue outer
108 }
109 }
110
111 m, err := r.ModifyRes(res)
112 if err != nil {
113 return nil, fmt.Errorf("apply %q: %v", r.RawRule, err)
114 }
115 if m {
116 appliedRules = append(appliedRules, *r)
117 }
118 }
119
120 return appliedRules, nil
121}
122
123func (nr *NetworkRules) Compact() {
124 nr.primaryStore.Compact()

Callers

nothing calls this directly

Calls 6

renderURLWithoutPortFunction · 0.85
filterFunction · 0.70
GetMethod · 0.65
ShouldMatchResMethod · 0.65
CancelsMethod · 0.65
ModifyResMethod · 0.65

Tested by

no test coverage detected