@@ -429,12 +429,14 @@ func (re *Engine) matches(r Rule, method, url string) bool {
429429 }
430430 }
431431 if ! methodMatches {
432+ re .logger .Info ("rule does not match" , "reason" , "method pattern mismatch" , "rule" , r .Raw , "method" , method , "url" , url )
432433 return false
433434 }
434435 }
435436
436437 parsedUrl , err := neturl .Parse (url )
437438 if err != nil {
439+ re .logger .Info ("rule does not match" , "reason" , "invalid URL" , "rule" , r .Raw , "method" , method , "url" , url , "error" , err )
438440 return false
439441 }
440442
@@ -448,13 +450,15 @@ func (re *Engine) matches(r Rule, method, url string) bool {
448450
449451 // If the host pattern is longer than the actual host, it's definitely not a match
450452 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 ))
451454 return false
452455 }
453456
454457 // Compare pattern with the end of labels (allowing subdomains)
455458 for i , lp := range r .HostPattern {
456459 labelIndex := len (labels ) - len (r .HostPattern ) + i
457460 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 ])
458462 return false
459463 }
460464 }
@@ -465,16 +469,19 @@ func (re *Engine) matches(r Rule, method, url string) bool {
465469
466470 // If the path pattern is longer than the actual path, definitely not a match
467471 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 ))
468473 return false
469474 }
470475
471476 // Each segment in the pattern must be either as asterisk or match the actual path segment
472477 for i , sp := range r .PathPattern {
473478 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 ])
474480 return false
475481 }
476482 }
477483 }
478484
485+ re .logger .Info ("rule matches" , "reason" , "all patterns matched" , "rule" , r .Raw , "method" , method , "url" , url )
479486 return true
480487}
0 commit comments