Forum Discussion
Abed_AL-R
Cirrostratus
Aug 28, 2020iRule | route to another pool according to URI
Hello guys I'm trying to write an iRule that route the traffic if the end user hit a specific URI. This specific URI has a pattern inside it and according to this pattern I'm doing the match. But h...
Simon_Blakely
Employee
Aug 31, 2020Set a cookie for the client that specifies the current branchcode.
Use the cookie value to determine what pool the client request is sent to.
When they make a request that changes the branchcode, change the cookie value to the new branchcode.
You could use the client IP and a subtable, but for HTTP a cookie is the appropriate mechanism for maintaining state.
Here is some example code - it works as expected, but you should check it out and adjust it to your requirements.
when HTTP_REQUEST {
set new_branchcode ""
log local0. "branchcode is [URI::query [string tolower [HTTP::uri]] "branchcode"]"
switch [URI::query [string tolower [HTTP::uri]] "branchcode"] {
123 {
HTTP::cookie remove "branchcode"
HTTP::cookie insert name "branchcode" value "123"
log local0. "updating branchcode cookie to 123"
set new_branchcode "123"
}
456 {
HTTP::cookie remove "branchcode"
HTTP::cookie insert name "branchcode" value "456"
log local0. "updating branchcode cookie to 456"
set new_branchcode "456"
}
}
log local0. "selecting the pool based on branchcode cookie [HTTP::cookie value {branchcode}]"
switch [HTTP::cookie value {branchcode}] {
123 {
# pool 123_pool
log local0. "pool is 123_pool"
}
456 {
# pool 456_pool
log local0. "pool is 456_pool"
}
default {
# select default pool
log local0. "pool is default pool"
}
}
}
when HTTP_RESPONSE {
if {![string equal $new_branchcode ""]} {
log local0. "sending a new cookie $new_branchcode"
HTTP::cookie insert name "branchcode" value $new_branchcode
}
}
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
