Forum Discussion
how to match against a list in v11?
- Aug 07, 2015
class match works only with datagroups. It does not work with Tcl lists. The drawbacks of not using datagroups include:
- class matching runs in O(1) time, so the size of the datagroup does not affect the search performance. This is not true for Tcl lists (though you should get something better than O(n) for large lists if you use a Tcl dictionary);
- using Tcl lists generally require "inflating" the lists before the command can operate on it, which consumes CPU and memory;
- modifying an iRule requires technicians and engineers to know code, at least to some degree, and the list elements cannot be changed via
tmshor the WebUI.
Having said that, to search a Tcl list, you can use the lsearch method:
when RULE_INIT { set static::endpoints [list /about /cblock] } when HTTP_REQUEST { if { [lsearch -glob $static::endpoint "[HTTP::uri]*"] != -1 } { pool cms } }There are other ways, but this is likely the simplest.
Oh, you know, mostly because I'm a dummy :). I reversed the meaning (my code uses the request-uri as a glob match pattern looking to see if any list member matches, which is not what you want at all). You'll have to do this as follows (it's O(n) and probably as good as one can get with non-exact matching, unhappily):
when RULE_INIT {
set static::endpoints [list /test /guest /pest]
}
when HTTP_REQUEST {
foreach ep $static::endpoints {
if { [HTTP::path] starts_with $ep } {
log local0. "I'M IN"
pool cms
return
}
}
}I was trying to use something similar to the code Vernon posted above but I get a TCL error every time the irule triggers:
err tmm[14228]: 01220001:3: TCL error: /Common/test_selective_cac - couldn't set loop variable: " [HTTP::path] starts_with $ep " while executing "foreach ep $static::endpoints { if { [HTTP::path] starts_with $ep
Any ideas?
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
