Forum Discussion

Jack_39703's avatar
Jack_39703
Icon for Nimbostratus rankNimbostratus
Jul 27, 2009

contains? starts_with? equals?

hi there

 

 

i have a existing iRule as follow

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] contains "/123/"} {

 

pool 123

 

}

 

elseif { [HTTP::uri] starts_with "/456/" } {

 

pool 456

 

}

 

else {

 

pool 789

 

}

 

}

 

 

But it does not work when using equals instead of contains/starts_with. Can anyone help? Thanks.

 

 

Btw, what is the difference between [HTTP::uri] and [HTTP::path]?
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Hi,

     

     

    You can read up on the two commands on their wiki pages:

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/HTTP__path.html

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/HTTP__uri.html

     

     

    Are some of the requests matching the wrong condition in the iRule? Or why are you wanting to change the tests to equals?

     

     

    Aaron
  • thx for your quick reply

     

     

    the reason i want to use equals because there will be new vs using /123_456
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    So which pool would you want a request for /123_456 to go to?

     

     

    Aaron
  • If for some reason "equals" isn't working for you, you might want to try a switch command with glob matching.

    when HTTP_REQUEST { 
       switch -glob [HTTP::uri] { 
         "*/123/*" { 
           pool 123 
         } 
         "/456/*" { 
           pool 456 
         } 
         default { 
           pool 789 
         } 
       } 
     }

    Make sure you don't have case comparison issues (ie. "/A" won't match "/a"). If you need mixed case, enclose the HTTP::uri with a "string tolower".

    And, if all else fails, throw in some log statements to help diagnose why your matches aren't succeeding. Could be there are some trailing GET variables in the URI that you aren't accounting for.

    -Joe

    -Joe
  • How about this?

     when HTTP_REQUEST {  
       switch -glob [HTTP::uri] {  
         "*/123/*" {  
           pool 123  
         }  
         "/456/*" {  
           pool 456  
         }  
         "/123_456*" { 
           pool pool_123456 
         } 
         default {  
           pool 789  
         }  
       }  
     }

    The first "*/123/*" should not match on "/123_456" so you should be set.

    -Joe
  • Hi

     

     

    I have a question relating to the speed of processing between the if ( starts_with)and switch (-glob). I know that switch is normall faster than an if else, but is it still faster with the glob?

     

     

    Anthony
  • Posted By anthony@qut on 09/19/2010 06:10 PM

     

    Hi

     

     

    I have a question relating to the speed of processing between the if ( starts_with)and switch (-glob). I know that switch is normall faster than an if else, but is it still faster with the glob?

     

     

    Anthony

     

     

    Everything I've seen says yes. You can use "timing" to check the CPU cycles. http://devcentral.f5.com/Default.aspx?tabid=63&articleType=ArticleView&articleId=123