(req *http.Request, res *http.Response)
| 84 | } |
| 85 | |
| 86 | func (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 |
| 103 | outer: |
| 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 | |
| 123 | func (nr *NetworkRules) Compact() { |
| 124 | nr.primaryStore.Compact() |
nothing calls this directly
no test coverage detected