Forum Discussion
iRule | route to another pool according to URI
Set 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
}
}
- Abed_AL-RAug 31, 2020
Cirrostratus
Thanks
I'll check it out.
In the mean time I provided alternative solution - with redirection to another VS the has different pool according to data group value
when HTTP_REQUEST { if { [class match -- [URI::query [string tolower [HTTP::uri]] "branchcode"] equals branchcode_Data ] } { HTTP::redirect https://qa.mywebsite.com/[HTTP::uri] } }
But definitely I will check your iRule to see if it answers our needs.
Much thanks to you. 🙂
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