Forum Discussion

MAbbas's avatar
MAbbas
Icon for Cirrus rankCirrus
Sep 01, 2018

Irule Match

hello - i have been trying to understand the condition match that happens in irules in the example below -- if the URI -is /foobar would it not match the first case and exit - Thanks switch -glob [HTTP::uri] { "/foo" { this will match on any string that starts with "/foo" } "bar" { this will match on any string that ends with "bar" } "/foobar[a-zA-Z]" { This will match with any string that starts with "/foobar" followed by any case character from a-z. } "/foo?bar" { this will match any string that starts with "/foo", followed by any character, and followed by and ending with "bar". } }

 

2 Replies

  • switch -glob [HTTP::uri] { "/foo*" { this will match on any string that starts with "/foo" }

     

    "bar" { this will match on any string that ends with "bar" }

     

    "/foobar[a-zA-Z]" { This will match with any string that starts with "/foobar" followed by any case character from a-z. }

     

    "/foo?bar" { this will match any string that starts with "/foo", followed by any character, and followed by and ending with "bar". } }

     

  • I'll include the code again for readability (with additional comments):

     

    switch -glob [HTTP::uri] { 
        "/foo*" { 
             this will match on any string that starts with "/foo" 
        }
        "bar" { 
             this will match on a string that equals "bar". The -glob operator allows you to include regex-like wildcards in the expressions. And since you didn't specify any here, the match is explicit.
        }
        "/foobar[a-zA-Z]" { 
             This will match with any string that starts with "/foobar" followed by any case character from a-z. Except that this condition will never be matched as log as the more generic "/foo*" expression is at the top.
        }
        "/foo?bar" { 
             this will match any string that starts with "/foo", followed by any character, and followed by and ending with "bar". Except that this condition will never be matched as log as the more generic "/foo*" expression is at the top.
        } 
    }

    Generally speaking, you should always try to put the least specific matches at the bottom of the conditional. With "/foo*" at the top, the bottom two expressions can never be matched.