Forum Discussion
Passing a header value to lb to pool
I am trying to load balance traffic according to a server response header value. I think I may be going way too deep into the woods here. Can you help a young Padawan with a direction please?
Here is what I have already: when RULE_INIT { set newpool ""; }
when HTTP_RESPONSE { if { [HTTP::header exists "X-Pool-type"] } { set newpool [HTTP::header value "X-Pool-type" ] log local0. "Header found to be $newpool" HTTP::cookie insert name "LBcookie" value "$newpool" } else { log local0. "Header not found" return } }
when HTTP_REQUEST { if { [HTTP::cookie exists "LBcookie"] } { set cookie_pool [HTTP::cookie value "LBcookie" ] log local0. "Header found to be $cookie_pool" pool $cookie_pool } else { log local0. "cookie not found" return } }
4 Replies
- lunitic_56137
Nimbostratus
Sorry, forgot to format the code section
Code when RULE_INIT { set newpool ""; } when HTTP_RESPONSE { if { [HTTP::header exists "X-Load-Balancer-Pool"] } { set newpool [HTTP::header value "X-Load-Balancer-Pool" ] log local0. "Header found to be $newpool" HTTP::cookie insert name "Load-Balancer-Pool-cookie" value "$newpool" } else { log local0. "Header not found $newpool" return } } when HTTP_REQUEST { if { [HTTP::cookie exists "Load-Balancer-Pool-cookie"] } { set cookie_pool [HTTP::cookie value "Load-Balancer-Pool-cookie" ] log local0. "Header found to be $cookie_pool" pool $cookie_pool } else { log local0. "pool not found" return } } - Chris_Wentland
Nimbostratus
At first glance, you are only directing to a pool in the HTTP_Request section. You are not actually setting persistence or directing to a specific node. Take a peek at this example which demonstrates how to set the pool member. Also, what unique value will you look at in the cookie? I'd also recommend encrypting the cookie just to obscure any internal detail that does not need to be plain text!
https://devcentral.f5.com/wiki/irules.manual_cookie_persistence.ashx
- Kevin_Stewart
Employee
A few questions:
-
Can you elaborate on why you're doing this?
-
Do you have a default pool assigned to the VIP? Without it the initial request, without the cookie, wouldn't know where to go.
-
What are the log messages you're getting, and where is it failing?
-
- Chris_Wentland
Nimbostratus
To decrypt/encrypt cookies... create values for your cookie name $ckname, and cookie password $ckpass in the client connected event.
when CLIENT_ACCEPTED { Name for the cookie to be inserted to maintain client session set ckname Encryption password to be used for encrypting / decrypting the user session cookie set ckpass } when HTTP_REQUEST { if {[HTTP::cookie exists $ckname]} { Decrypt the cookie so we can use the values in it HTTP::cookie decrypt $ckname $ckpass 128 } } when HTTP_RESPONSE { Set up your cookie details here Now to encrypt your cookie HTTP::cookie encrypt $ckname $ckpass 128 }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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