Forum Discussion
Syntax of "switch" statement
I have seen some switch statements in our F5 rules that seem to be using "else" instead of the "default" keyword to catch all unmatched searches. Based on documentation, it would seem to me that the interpreter would merely attempt to match the string to "else" and fail instead of performing default action. My question is, is this an undocumented feature that works as the default keyword in F5? In other words, how does the interpreter treat the "else" statement in the example below?
when HTTP_REQUEST { switch -glob [HTTP::uri] { somesvc { drop } /mysvc* {pool my_pool_10010} / {redirect to https://somewhere.else.com/their_service} else { drop } } }
5 Replies
- nitass
Employee
is this an undocumented feature that works as the default keyword in F5? In other words, how does the interpreter treat the "else" statement in the example below?
isn't else interpreted as literal?
- nitass
Employee
e.g.
root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule quux ltm rule quux { when HTTP_REQUEST { switch -glob [HTTP::uri] { somesvc { log local0. "[HTTP::uri] - somesvc"; return } /mysvc* { log local0. "[HTTP::uri] - /mysvc*"; return } / { log local0. "[HTTP::uri] - /"; return } else { log local0. "[HTTP::uri] - else"; return } } log local0. "[HTTP::uri] - not match" } } [root@ve11a:Active:In Sync] config tail -f /var/log/ltm Jan 26 09:17:16 ve11a info tmm1[11129]: Rule /Common/quux : /mysvc/something - /mysvc* Jan 26 09:17:18 ve11a info tmm[11129]: Rule /Common/quux : /somethingelse - not match- Michael_Benzing
Nimbostratus
Thanks for the test results! My initial thoughts were that this was being treated as a literal and not a keyword.
- nitass_89166
Noctilucent
e.g.
root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule quux ltm rule quux { when HTTP_REQUEST { switch -glob [HTTP::uri] { somesvc { log local0. "[HTTP::uri] - somesvc"; return } /mysvc* { log local0. "[HTTP::uri] - /mysvc*"; return } / { log local0. "[HTTP::uri] - /"; return } else { log local0. "[HTTP::uri] - else"; return } } log local0. "[HTTP::uri] - not match" } } [root@ve11a:Active:In Sync] config tail -f /var/log/ltm Jan 26 09:17:16 ve11a info tmm1[11129]: Rule /Common/quux : /mysvc/something - /mysvc* Jan 26 09:17:18 ve11a info tmm[11129]: Rule /Common/quux : /somethingelse - not match- Michael_Benzing
Nimbostratus
Thanks for the test results! My initial thoughts were that this was being treated as a literal and not a keyword.
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