Forum Discussion
Livius
Cirrus
Jan 19, 2017Error code when no conditions match in iRule
Hi,
I have the following iRule atached to a default HTTP profile
ltm rule /Common/test1_iRule {
when RULE_INIT
{
set static::RoutingInfo "test1"
log local0. "------------------------------ INIT ------------------------------------"
log local0. "RoutingInfo is $RoutingInfo"
}
when XML_CONTENT_BASED_ROUTING
{
for {set i 0} { $i < $XML_count } {incr i} {
Routing by RoutingLabel
log local0. "XML_queries $XML_queries($i)"
log local0. "XML_values $XML_values($i)"
if { ($XML_queries($i) contains "RoutingLabel")} {
if { ($XML_values($i) eq "test1")} {
set static::RoutingInfo "test1"
pool test1_p
break
} elseif {($XML_values($i) eq "test1_encr")} {
set static::RoutingInfo "test1_encr"
pool test1_encr_p
break
} elseif {($XML_values($i) contains "SOAPtest")} {
set static::RoutingInfo "SOAPtest"
pool test1_sim_p
break
} elseif {($XML_values($i) contains "test2")} {
set static::RoutingInfo "test2"
pool test2_p
break
}
}
}
log local0. "RoutingInfo is $static::RoutingInfo after selecting pools"
}I need to send HTTP error code 422 in case there is no value in the request, or a value that matches my conditions. I tried with various "else" conditions but no luck yet..
Regards.
1 Reply
- JG
Cumulonimbus
Would this work for you?
ltm rule /Common/test1_iRule { when RULE_INIT { log local0. "------------------------------ INIT ------------------------------------" } when XML_CONTENT_BASED_ROUTING { set ValueFound 0 set RoutingInfo "0" for {set i 0} { $i < $XML_count } {incr i} { Routing by RoutingLabel log local0. "XML_queries $XML_queries($i)" log local0. "XML_values $XML_values($i)" if { ($XML_queries($i) contains "RoutingLabel")} { if { ($XML_values($i) eq "test1")} { pool test1_p set RoutingInfo "test1" set ValueFound 1 break } elseif {($XML_values($i) eq "test1_encr")} { pool test1_encr_p set ValueFound 1 set RoutingInfo "test1_encr" break } elseif {($XML_values($i) contains "SOAPtest")} { pool test1_sim_p set RoutingInfo "SOAPtest" set ValueFound 1 break } elseif {($XML_values($i) contains "test2")} { pool test2_p set ValueFound 1 set RoutingInfo "test2" break } } } log local0. "RoutingInfo is $RoutingInfo after selecting pools" } when LB_FAILED { if { $ValueFound == 0 } { HTTP::respond 422 Connection close } } }?
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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