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.
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?
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.
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).