Forum Discussion

kco's avatar
kco
Icon for Altostratus rankAltostratus
Apr 01, 2009

question about matchclass and "contains"

 

I would like to use matchclaass function with the "contains" operator. We want to shunt requests from Googlebot User-Agent to a separate pool of servers. I've searched DevCentral and found many examples to use as a model.

 

 

My question is about whether to use:

 

matchclass

 

or

 

matchclass

 

 

The page http://devcentral.f5.com/wiki/default.aspx/iRules/matchclass.html has a caution and says to use the former syntax for the type of comparison that we would like to do.

 

 

Quote:

 

This example will will return the index of the first row that has the string "green" anywhere in it:

 

[matchclass $::data_group contains "green"]

 

EndQuote:

 

 

Yet every iRule example that I found on the site has the $::data_group on the right hand side of the contains operator. And even the contains example on that page above has it on the rhs.

 

 

Searches on Google did not yield a reference that resolves the dilemma. Can anyone in the Forum answer this for me?

 

 

Thanks.

 

 

...Kevin O'Neil

 

OCLC Inc.

 

Dublin OH USA

 

2 Replies

  • I personally would choose "[matchclass $::data_group contains "green"]. My thoughts are that if you mispell in the datagroup you don't render your iRule invalid now or down the road.

     

     

    My 2 cents

     

     

    CB

     

     

  • spark_86682's avatar
    spark_86682
    Historic F5 Account
    It's not that either form is right or wrong, it's that they do different things, and you should use the form that does the thing you want.

    The iRules Wiki entry on this seems to explain the difference pretty clearly, but I'll use the "Controlling Bots" iRule as another example (http://devcentral.f5.com/wiki/default.aspx/iRules/ControllingBots.html).

    That iRule has a list of User-Agents in a class (called "bots") and an iRule that looks like:

     
     when HTTP_REQUEST { 
       if { [matchclass [string tolower [HTTP::header User-Agent]] contains $::bots] } { 
         pool slow_webbot_pool 
       } else { 
         pool default_pool 
       } 
     } 
     

    This uses the "matchclass " form, which sees if the value contains any of the items in the data group. For example, one item in the data group is "googlebot", so if the User-Agent string was "googlebot", "I am a googlebot", "googlebot 2000", or "This is googlebot v1.2.3", then it would match. If the User-Agent string was just "bot", it would not match (because ["bot" contains "googlebot"] returns false).

    If the rule used the other form ("matchclass "), then the comparison would go in the other direction. So, if the User-Agent string was "googlebot", or "google", or "bot", then it would match (because ["googlebot" contains "bot"] returns true), but if it was "I am a googlebot", "googlebot 2000", or "This is googlebot v1.2.3", it would not match (because ["googlebot" contains "googlebot 2000"] returns false).

    Make sense?