Forum Discussion

Mohammad_Hossei's avatar
Mohammad_Hossei
Icon for Nimbostratus rankNimbostratus
Jun 13, 2018

switch -glob issue with URI tolower string

Hi Guys, I expect this irule to be working for me based on my URI but it is not working. it only supports lowercases and can't detect anything in Capital like Lion or TIGER. Please help if you have any idea.

 

when HTTP_REQUEST { switch -glob [string tolower [HTTP_uri]] { "/lion" { pool test1 member 1.1.1.1:8080 } "/tiger" { pool test1 member 1.1.1.2:8080 } "/mouse*" { pool test1 member 1.1.1.3:8080 } default { HTTP::redirect "/tiger" } } }

 

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    You had a typo; also I'd use [HTTP::path] instead.

        when HTTP_REQUEST { 
        switch -glob [string tolower [HTTP::path]] {
            "/lion" { 
                        pool test1 member 1.1.1.1 8080 
            }
            "/tiger" { 
                         pool test1 member 1.1.1.2 8080 
            }
            "/mouse*" { 
                          pool test1 member 1.1.1.3 8080 
            }
            default { 
                        HTTP::redirect "/tiger" 
            }
        }
    }
    
  • The problem when you anonymize the code is to check if the code you applied is correct!

     

    if you convert URI or PATH (as suggested Jie) to lowercase, the switch condition must be lowercase.

     

    for example :

     

    when HTTP_REQUEST { 
        switch -glob [string tolower [HTTP_uri]] { 
            "/lion" { pool test1 member 1.1.1.1:8080 }  
            --> will match /lion /Lion /LION /LioN
            "/Tiger" { pool test1 member 1.1.1.2:8080 } 
            --> will never match because you compare a lowercase string with a string with a uppercase character
            "/mouse*" { pool test1 member 1.1.1.3:8080 }  
            --> will match /mouse /Mouse / /MOUSE /mousekdjghflh /MOuse/images/front.png
            default { HTTP::redirect "/tiger" } 
        } 
    }