(req *http.Request)
| 22 | } |
| 23 | |
| 24 | func (nr *NetworkRules) ModifyReq(req *http.Request) (appliedRules []rule.Rule, shouldBlock bool, redirectURL string) { |
| 25 | reqURL := renderURLWithoutPort(req.URL) |
| 26 | |
| 27 | primaryRules := nr.primaryStore.Get(reqURL) |
| 28 | primaryRules = filter(primaryRules, func(r *rule.Rule) bool { |
| 29 | return r.ShouldMatchReq(req) |
| 30 | }) |
| 31 | if len(primaryRules) == 0 { |
| 32 | return nil, false, "" |
| 33 | } |
| 34 | |
| 35 | exceptions := nr.exceptionStore.Get(reqURL) |
| 36 | exceptions = filter(exceptions, func(er *exceptionrule.ExceptionRule) bool { |
| 37 | return er.ShouldMatchReq(req) |
| 38 | }) |
| 39 | |
| 40 | initialURL := req.URL.String() |
| 41 | |
| 42 | var query url.Values |
| 43 | if req.URL.RawQuery != "" { |
| 44 | query = req.URL.Query() |
| 45 | } |
| 46 | |
| 47 | var queryModified bool |
| 48 | outer: |
| 49 | for _, r := range primaryRules { |
| 50 | for _, ex := range exceptions { |
| 51 | if ex.Cancels(r) { |
| 52 | continue outer |
| 53 | } |
| 54 | } |
| 55 | if r.ShouldBlockReq(req) { |
| 56 | return []rule.Rule{*r}, true, "" |
| 57 | } |
| 58 | |
| 59 | modified := r.ModifyReq(req) |
| 60 | if query != nil { |
| 61 | if r.ModifyReqQuery(query) { |
| 62 | queryModified = true |
| 63 | modified = true |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | if modified { |
| 68 | appliedRules = append(appliedRules, *r) |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | if queryModified { |
| 73 | // Re-encoding the same query params may cause subtle normalization changes |
| 74 | // (e.g. parameter reordering), so only do it if they were actually modified. |
| 75 | req.URL.RawQuery = query.Encode() |
| 76 | } |
| 77 | |
| 78 | finalURL := req.URL.String() |
| 79 | if initialURL != finalURL { |
| 80 | return appliedRules, false, finalURL |
| 81 | } |
nothing calls this directly
no test coverage detected