Forum Discussion
amebiz_142234
May 25, 2018Nimbostratus
irule pool selection based on dynamic cookie value
Hi, my scenario: i want to select a pool based on a cookie value - that works as aspected when_HTTP_REQUEST {
if { [HTTP::cookie exists "myCookie"] } {
switch -glob [HTTP::cookie value "myCook...
Stanislas_Piro2
Jun 06, 2018Cumulonimbus
Hi,
you can use following code:
when CLIENT_ACCEPTED {
set default_pool [LB::server pool]
}
when_HTTP_REQUEST {
set target ""
if { [string tolower [HTTP::path]] equals "/foo/" } {
set target "foo"
} elseif { [string tolower [HTTP::path]] equals "/bar/" } {
set target "bar"
}
if { [HTTP::cookie exists "myCookie"] && $target equals "" } {
target is empty, get target from cookie
set target [HTTP::cookie value "myCookie"]
} elseif { (![HTTP::cookie exists "myCookie"] && $target ne "") || [HTTP::cookie value "myCookie"] ne $target } {
cookie value is empty or value is wrong, inject cookie with right value is response.
set inject_cookie $target
}
switch $target {
foo {pool foo}
bar {pool bar}
default {pool $default_pool}
}
}
when HTTP_RESPONSE {
if {[info exists inject_cookie]} {
HTTP::cookie insert name myCookie value $inject_cookie
unset inject_cookie
}
}
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