I'm attempting to write a generic iRule to send traffic for a URI to a specific pool. I will use this over "many" virtuals with "many" URIs.
What's the most efficient way to check for the / at the end of each URI so that /foo and /foobar are not matched by whichever hits first but the URI still works in a browser without the trailing /?
Any other easy way to do this? I want people to easily be able to modify the class and to have a central location for this data. Can I use findclass or matchclass to make this faster?
It sounds like FishNiX wants to get the longest match though. You could loop through the class row by row and track the curent longest match of the host and URI until you get through all rows. Or another option would be to combine the first two columns of the class and then use lindex -index -descending to sort the class as a list. This would probably only work in 9.x though, as you can't access a datagroup/class as a standard TCL list in 10.x.
log local0. "lsort: [lsort -decreasing -index 0 $::hooleya_host_uri_pool_selector_class]"
log local0. "Found longest match: $line; pool: [getfield $row " " 2]"
For an example of manually tracking the longest match, you can use Deb's example below. This example would also work with the class command in v10.
I've been thinking about it as the most exact match of the first two entries in the class. Both HTTP::host and HTTP::uri need to match "the most" and if I ensure it ends with a "/" it will always work (as long as we never try to match /foo/foo.jsp I suppose).... maybe "longest" is the more correct way.
log local0. "lsort: [lsort -decreasing -index 0 $::host_uri_pool_selector_class]"
Will this work if there are multiple entries for the HTTP::host in the class? I think it will only return the first row found right?
Yes findclass will search the class object and find a match and then return the row on that match to the variable "row"
I understand, but wont it only return 1 row (the first it finds)? I'm my case, I could have many rows with the same HTTP::host.
In that case I think your code closely matches to what you want.