Forum Discussion
Greg_Ryan_33844
Nimbostratus
Jul 20, 2010iRule to set a cookie based on url
Hi, this is one of my first iRules and I am completely at a loss. What I am trying to do is set a cookie based on a 'contains' in the url. Once the cookie is set then I want to switch the pool based on the cookie value. I can get the second part to work, what I can't seem to do is to set a cookie based on an if statement. Has anyone done anything like this?
when HTTP_REQUEST {
if { [HTTP::uri] contains "newAdmin=1" } {
set newadmin_cookie "1"
pool 81_pool
}
elseif { [HTTP::uri] contains "newAdmin=0" } {
set newadmin_cookie "0"
pool server_pool
}
if { ([HTTP::cookie value "newadmin"] equals "1") } {
pool 81_pool
}
elseif { ([HTTP::cookie value "newadmin"] equals "0") } {
pool server_pool
}
}
when HTTP_RESPONSE {
HTTP::cookie insert name "newadmin" value $newadmin_cookie path "/"
}
- hoolio
Cirrostratus
Hi Greg,when HTTP_REQUEST { Initialize the newadmin cookie value to something other than 0 or 1 set newadmin_cookie undefined log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] request to [HTTP::host][HTTP::uri]" Check the query string for a parameter named newAdmin Use a workaround described in http ://devcentral.f5.com/wiki/default.aspx/iRules/uri__query switch [URI::query "?&[HTTP::query] &newAdmin] { "0" { newAdmin parameter set to 0 set newadmin_cookie "0" pool server_pool log local0. "[IP::client_addr]:[TCP::client_port]: newAdmin param match for 0, using server_pool" } "1" { newAdmin parameter set to 1 set newadmin_cookie "1" pool 81_pool log local0. "[IP::client_addr]:[TCP::client_port]: newAdmin param match for 1, using 81_pool" } default { newAdmin parameter not set to 0 or 1 Check for a newadmin cookie switch [HTTP::cookie value "newadmin"] { "0" { newAdmin cookie set to 0 set newadmin_cookie "0" pool server_pool log local0. "[IP::client_addr]:[TCP::client_port]: newAdmin cookie match for 0, using server_pool" } "1" { newAdmin cookie set to 1 set newadmin_cookie "1" pool 81_pool log local0. "[IP::client_addr]:[TCP::client_port]: newAdmin cookie match for 1, using 81_pool" } default { No match for newAdmin parameter or cookie. Take some default action? log local0. "[IP::client_addr]:[TCP::client_port]: No match on newAdmin parameter or cookie" } } } } } when HTTP_RESPONSE { HTTP::cookie insert name "newadmin" value $newadmin_cookie path "/" }
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