Tadaoki_237078
Dec 17, 2015Nimbostratus
iRules: Pool selection by URI and cookies
Hello everyone
I want to make an iRule which;
1) Select a pool by URI during first http request 2) For the subsequent requests for css and graphic files(with URI different than the first request), load balance by cookie.
What I got so far:
when HTTP_REQUEST {
log -noname local0. "HTTP_REQUEST URI: [HTTP::uri]"
switch -glob [substr [ HTTP::uri ] 1]
{
"foo/*" { pool pool_foo
The server have all content in /
HTTP::uri [string map {"/foo/" "/"} [HTTP::uri]]
log -noname local0. "Selected pool_foo by URI"
}
"bar/*" {
pool pool_bar
HTTP::uri [string map {"/bar/" "/"} [HTTP::uri]]
log -noname local0. "Selected pool_bar by URI"
}
default {
switch -glob [HTTP::cookie names]
{
"*pool_foo" { pool pool_foo
log -noname local0. "Selected pool_foo by cookie"
}
"*pool_bar" { pool pool_bar
log -noname local0. "Selected pool_bar by cookie"
}
default {
log -noname local0. "NO MATCH by cookie.."
}
}
}
}
}
The problem with this approach is that when the client(browser) has multiple(or all) cookies, the default part of the switch will always load balance to pool_foo.
I have two ideas to go about this problem:
1)Delete cookies so that I only have the one cookie I need at all times.
2)Make a variable to determine the "current" cookie across events.
Any help is appreciated. Thank you.
-Kai