Forum Discussion
Andrea_Arquint
Oct 25, 2010Nimbostratus
stop processing further irules on condition match
Hi all
I have some irules assigned to a virtual server.
The first irule is cheking some condition. How can I stop processing all further irules if a specific condition matches in t...
hooleylist
Dec 27, 2010Cirrostratus
You could use an iRule like this to detect if a prior iRule has changed the pool from the virtual server's default pool or issued an HTTP redirect (using HTTP::redirect) or response (using HTTP::respond):
when CLIENT_ACCEPTED priority 1 {
Ensure this event runs first to save the VS's default pool name
set default_pool [LB::server pool]
}
when HTTP_REQUEST priority 999 {
Ensure this event runs after any iRules which should take precedence over this one
Check if the currently selected pool has changed or an HTTP redirect/response has been triggered already.
if { ([LB::server pool] ne $default_pool) or [catch {HTTP::payload replace 0 0 {}}] } {
set already_responded 1
} else {
set already_responded 0
}
if {$already_responded == 0}{
Do something like select a pool or redirect the client
}
}
Or if you don't care about pool changes and just want to detect a redirect/respond, you could simplify the iRule:
when HTTP_REQUEST priority 999 {
Ensure this event runs after any iRules which should take precedence over this one
Check if an HTTP redirect/response has been triggered already.
if { [catch {HTTP::payload replace 0 0 {}}] } {
set already_responded 1
} else {
set already_responded 0
}
if {$already_responded == 0}{
Do something like select a pool or redirect the client
}
}
Both examples attempt to insert nothing in the request payload. If a redirect/response has already been sent in an iRule, catch traps a runtime error and a variable is set to track it.
Aaron
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects