Forum Discussion
irule to insert cookie
I have 2 pools which are specific to 2 different purposes. Based on qurey string parameters(spentityids) my irule will select which pool should the client go to. I have a requirement where the client might have to navigate to a third party vendor site from the native primary site, so while returning back to the primary site(return navigation) I need to have the client reach the same pool that served him primarily. So I will need to have my irule insert a cookie in http response with a value 0 or 1 for each pool, so if client comes with cookie value 0 it goes to one pool and with value 1 it goes to another pool. Can anyone help how to accomplish task?
1 Reply
- nitass
Employee
not sure if this is what you are looking for. anyway, hope it helps.[root@ve10:Active] config b virtual bar list virtual bar { snat automap destination 172.28.19.252:80 ip protocol 6 rules myrule persist cookie profiles { http {} tcp {} } } [root@ve10:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { if { [HTTP::cookie exists cpool] } { switch [HTTP::cookie cpool] { 0 { set cpool 0; pool foo0 } 1 { set cpool 1; pool foo1 } default { do soemthing reject } } } else { if { [URI::query "?&[HTTP::query]" "spentityids"] == "value0" } { set cpool 0 pool foo0 } else { set cpool 1 pool foo1 } } } when HTTP_RESPONSE { HTTP::cookie insert name cpool value $cpool } } [root@ve10:Active] config b pool foo0 list pool foo0 { members 200.200.200.101:80 {} } [root@ve10:Active] config b pool foo1 list pool foo1 { members 200.200.200.111:80 {} } [root@ve10:Active] config curl -i "http://172.28.19.252/?spentityids=value0&something=bhabhabha" HTTP/1.1 200 OK Date: Sat, 26 Jan 2013 05:20:00 GMT Server: Apache/2.2.3 (CentOS) Last-Modified: Sat, 27 Oct 2012 03:22:35 GMT ETag: "4183f3-59-f28f94c0" Accept-Ranges: bytes Content-Length: 89 Content-Type: text/html; charset=UTF-8 Set-Cookie: BIGipServerfoo0=1707657416.20480.0000; path=/ Set-Cookie: cpool=0; This is 101 host. [root@ve10:Active] config curl -i "http://172.28.19.252/?spentityids=somethingelse&something=bhabhabha" HTTP/1.1 200 OK Date: Sat, 26 Jan 2013 04:55:47 GMT Server: Apache/2.2.3 (CentOS) Last-Modified: Wed, 30 Nov 2011 05:42:33 GMT ETag: "418416-30-33ce6440" Accept-Ranges: bytes Content-Length: 48 Content-Type: text/html; charset=UTF-8 Set-Cookie: BIGipServerfoo1=1875429576.20480.0000; path=/ Set-Cookie: cpool=1; This is 111 host. [root@ve10:Active] config curl -i http://172.28.19.252/ -H "Cookie: cpool=0" HTTP/1.1 200 OK Date: Sat, 26 Jan 2013 05:21:44 GMT Server: Apache/2.2.3 (CentOS) Last-Modified: Sat, 27 Oct 2012 03:22:35 GMT ETag: "4183f3-59-f28f94c0" Accept-Ranges: bytes Content-Length: 89 Content-Type: text/html; charset=UTF-8 Set-Cookie: BIGipServerfoo0=1707657416.20480.0000; path=/ Set-Cookie: cpool=0; This is 101 host. [root@ve10:Active] config curl -i http://172.28.19.252/ -H "Cookie: cpool=1" HTTP/1.1 200 OK Date: Sat, 26 Jan 2013 04:56:49 GMT Server: Apache/2.2.3 (CentOS) Last-Modified: Wed, 30 Nov 2011 05:42:33 GMT ETag: "418416-30-33ce6440" Accept-Ranges: bytes Content-Length: 48 Content-Type: text/html; charset=UTF-8 Set-Cookie: BIGipServerfoo1=1875429576.20480.0000; path=/ Set-Cookie: cpool=1; This is 111 host.
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