Forum Discussion
hooleylist
Nov 03, 2009Cirrostratus
Sure, for switch cases that you want to take the same action for, you can add them using -
For details, you can check the TCL switch page: http://www.tcl.tk/man/tcl8.4/TclCmd/switch.htm
Here are a few example of using glob style patterns:
switch -glob $some_string {
"1" -
"2" -
"3" {
Matched 1, 2 or 3
}
"[4-6]" {
Matched 4, 5 or 6
}
"[d-f]" {
Matched d, e or f
}
"z*" {
Matched anything starting with z
}
"*z" {
Matched anything ending with z
}
default {
No match. Default case
}
}
when HTTP_REQUEST {
log local0. "[IP::client_addr]:[TCP::client_port]: New [HTTP::method] request to [HTTP::host][HTTP::uri]"
Check requested host header value
if {[string tolower [HTTP::host]] eq "test.website.com"} {
log local0. "[IP::client_addr]:[TCP::client_port]: Matched Host check. Checking URI now."
Check the requested URI
switch -glob [HTTP::uri] {
"/Three*" -
"/Four*" {
Requested URI started with /Three or /Four
log local0. "[IP::client_addr]:[TCP::client_port]: Matched URI check for /Three or /Four. Allowing request to go to pool"
}
default {
HTTP::respond 301 Location "http://test.website2.com[HTTP::uri]"
log local0. "[IP::client_addr]:[TCP::client_port]: No URI match. Redirecting to http://test.website2.com[HTTP::uri]"
}
}
}
}
Aaron