MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / MatchRequest

Method MatchRequest

internal/waf/rule.go:231–288  ·  view source on GitHub ↗
(req requests.Request)

Source from the content-addressed store, hash-verified

229}
230
231func (this *Rule) MatchRequest(req requests.Request) (b bool, hasRequestBody bool, err error) {
232 if this.singleCheckpoint != nil {
233 value, hasCheckedRequestBody, err, _ := this.singleCheckpoint.RequestValue(req, this.singleParam, this.CheckpointOptions, this.Id)
234 if hasCheckedRequestBody {
235 hasRequestBody = true
236 }
237 if err != nil {
238 return false, hasRequestBody, err
239 }
240
241 // execute filters
242 if len(this.ParamFilters) > 0 {
243 value = this.execFilter(value)
244 }
245
246 // if is composed checkpoint, we just returns true or false
247 if this.singleCheckpoint.IsComposed() {
248 return types.Bool(value), hasRequestBody, nil
249 }
250
251 return this.Test(value), hasRequestBody, nil
252 }
253
254 var value = configutils.ParseVariables(this.Param, func(varName string) (value string) {
255 var pieces = strings.SplitN(varName, ".", 2)
256 var prefix = pieces[0]
257 point, ok := this.multipleCheckpoints[prefix]
258 if !ok {
259 return ""
260 }
261
262 if len(pieces) == 1 {
263 value1, hasCheckRequestBody, err1, _ := point.RequestValue(req, "", this.CheckpointOptions, this.Id)
264 if hasCheckRequestBody {
265 hasRequestBody = true
266 }
267 if err1 != nil {
268 err = err1
269 }
270 return this.stringifyValue(value1)
271 }
272
273 value1, hasCheckRequestBody, err1, _ := point.RequestValue(req, pieces[1], this.CheckpointOptions, this.Id)
274 if hasCheckRequestBody {
275 hasRequestBody = true
276 }
277 if err1 != nil {
278 err = err1
279 }
280 return this.stringifyValue(value1)
281 })
282
283 if err != nil {
284 return false, hasRequestBody, err
285 }
286
287 return this.Test(value), hasRequestBody, nil
288}

Callers 2

TestRule_Init_SingleFunction · 0.95
TestRule_Init_CompositeFunction · 0.95

Calls 5

execFilterMethod · 0.95
TestMethod · 0.95
stringifyValueMethod · 0.95
RequestValueMethod · 0.65
IsComposedMethod · 0.65

Tested by 2

TestRule_Init_SingleFunction · 0.76
TestRule_Init_CompositeFunction · 0.76