findclass¶
Description¶
Searches a data group list for a member whose key matches the
specified string, and if a match is found, returns the data-group
member string.
Note: findclass has been
deprecated
in v10 in favor of the new class commands. The class
command offers better functionality and performance than findclass
Only the key value of the data group list member (the portion up to
the first separator character, which defaults to space unless
otherwise specified) is compared to the specified string to determine
a match.
If a match is found, and no separator character is specified, the
command returns the entire member value associated with the matched
key (including the key).
If a match is found and a separator is specified, the data group
member is split at the first separator, and the portion of the list
member following the first separator is returned.
Note that you should not use a $:: or :: prefix on the datagroup name
when using the class command (or in any datagroup reference on 9.4.4
or later).
In v9.4.4 - 10, using $::datagroup_name will work but demote the
virtual server from running on all TMMs. For details, see the CMP
compatibility page.
In v11, using $::datagroup_name will result in a runtime error and
TCP reset being sent to the client!
Syntax¶
findclass <string> <data group> [<separator>]
findclass <string> <data group>¶
- Searches for a member whose key exactly matches . If a match is found, it returns the entire data group list member intact, including the key and the separator.
findclass <string> <data group> <separator>¶
- Searches for a member whose key exactly matches . If a match is found, it returns the portion of the data group list member following the first instance of .
Examples¶
class dest_pairs_dg {
"8080 proxy"
"8020 snatpool2"
"8081 proxy2"
"8084 proxy3"
"8140 snatpool6"
}
when CLIENT_ACCEPTED {
set my_spool [findclass [TCP::local_port] dest_pairs_dg " "]
if { $my_spool ne "" } {
snatpool $my_spool
}
}
class URIredirects_dg {
"/dir1/dir2/dir3/ http://somehost.somewhere.com/redirect_target.html"
"/dir4/dir5/dir6/ http://someotherhost.nowhere.com/redirect_target.html"
}
when HTTP_REQUEST {
set location [findclass [HTTP::uri] URIredirects_dg " "]
if { $location ne "" }
HTTP::redirect $location
}
}
class myRedirects_dg {
"host1.domain.com 302 https://securehost.domain.com"
"host2.domain.com 301 https://securehost2.domain.com"
}
when HTTP_REQUEST {
# Check if there is a class entry which starts with the requested URI
set row [findclass [string tolower [HTTP::host]] myRedirects_dg]
# Check if there was a matched row
if { $row ne "" }{
# Send a response using the status and location from the class
HTTP::respond [getfield $row " " 2] Location [getfield $row " " 3][HTTP::uri] Connection Close
# Clear the row variable
unset row
}
}