@@ -429,12 +429,14 @@ func (re *Engine) matches(r Rule, method, url string) bool {
429
429
}
430
430
}
431
431
if ! methodMatches {
432
+ re .logger .Info ("rule does not match" , "reason" , "method pattern mismatch" , "rule" , r .Raw , "method" , method , "url" , url )
432
433
return false
433
434
}
434
435
}
435
436
436
437
parsedUrl , err := neturl .Parse (url )
437
438
if err != nil {
439
+ re .logger .Info ("rule does not match" , "reason" , "invalid URL" , "rule" , r .Raw , "method" , method , "url" , url , "error" , err )
438
440
return false
439
441
}
440
442
@@ -448,13 +450,15 @@ func (re *Engine) matches(r Rule, method, url string) bool {
448
450
449
451
// If the host pattern is longer than the actual host, it's definitely not a match
450
452
if len (r .HostPattern ) > len (labels ) {
453
+ re .logger .Info ("rule does not match" , "reason" , "host pattern too long" , "rule" , r .Raw , "method" , method , "url" , url , "pattern_length" , len (r .HostPattern ), "hostname_labels" , len (labels ))
451
454
return false
452
455
}
453
456
454
457
// Compare pattern with the end of labels (allowing subdomains)
455
458
for i , lp := range r .HostPattern {
456
459
labelIndex := len (labels ) - len (r .HostPattern ) + i
457
460
if string (lp ) != labels [labelIndex ] && lp != "*" {
461
+ re .logger .Info ("rule does not match" , "reason" , "host pattern label mismatch" , "rule" , r .Raw , "method" , method , "url" , url , "expected" , string (lp ), "actual" , labels [labelIndex ])
458
462
return false
459
463
}
460
464
}
@@ -465,16 +469,19 @@ func (re *Engine) matches(r Rule, method, url string) bool {
465
469
466
470
// If the path pattern is longer than the actual path, definitely not a match
467
471
if len (r .PathPattern ) > len (segments ) {
472
+ re .logger .Info ("rule does not match" , "reason" , "path pattern too long" , "rule" , r .Raw , "method" , method , "url" , url , "pattern_length" , len (r .PathPattern ), "path_segments" , len (segments ))
468
473
return false
469
474
}
470
475
471
476
// Each segment in the pattern must be either as asterisk or match the actual path segment
472
477
for i , sp := range r .PathPattern {
473
478
if string (sp ) != segments [i ] && sp != "*" {
479
+ re .logger .Info ("rule does not match" , "reason" , "path pattern segment mismatch" , "rule" , r .Raw , "method" , method , "url" , url , "expected" , string (sp ), "actual" , segments [i ])
474
480
return false
475
481
}
476
482
}
477
483
}
478
484
485
+ re .logger .Info ("rule matches" , "reason" , "all patterns matched" , "rule" , r .Raw , "method" , method , "url" , url )
479
486
return true
480
487
}
0 commit comments