# parse cookie content company code to specific  pools?

**URL:** <https://community.f5.com/t/parse-cookie-content-company-code-to-specific-pools/25481>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [April 16, 2013, 10:17pm UTC](https://community.f5.com/t/parse-cookie-content-company-code-to-specific-pools/25481 "2013-04-16T22:17:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JCMATTOS\_41723](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@JCMATTOS\_41723](https://community.f5.com/u/JCMATTOS_41723)\
**Post date:** [April 16, 2013, 10:17pm UTC](https://community.f5.com/t/parse-cookie-content-company-code-to-specific-pools/25481/1 "2013-04-16T22:17:27Z")

</div>

We require a special iRule to parse the cookie for company codes and direct them to a specific pool. For example each client will have an unencrypted cookie that will contain a unique company code ie. (A1, B1, and C1). We would like to direct clients to a specific pool based on that company code.

A1 goes to pool POOL1

B1 goes to pool POOL2

C1 goes to pool POOL3

and so forth…

Is there something we could craft that would allow this logic to work properly? Any help is greatly appreciated. Thx!

---

<div class="post-metadata">

**Author:** ![Kevin\_Stewart](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kevin_stewart/32/15267_2.png) [@Kevin\_Stewart](https://community.f5.com/u/Kevin_Stewart)\
**Post date:** [April 16, 2013, 10:35pm UTC](https://community.f5.com/t/parse-cookie-content-company-code-to-specific-pools/25481/2 "2013-04-16T22:35:36Z")

</div>

A cookie is generally a key-value pair, so is the A1, B1, C1 a key or a value?

For example, if it’s a value (assuming the cookie name is “COMPANY\_CODE”):

```tcl
when HTTP_REQUEST {
    switch { [HTTP::cookie "COMPANY_CODE"] } {
        "A1" { pool POOL1 } 
        "B1" { pool POOL2 }
        "C1" { pool POOL3 }
        default { reject }
    }
}

```

Of course this doesn’t work if the cookie is passed AFTER the initial request. Do you have an out-of-band mechanism to distribute the cookies, or will the user connection initially without the cookie and hope to get one at some point?

---

<div class="post-metadata">

**Author:** ![JCMATTOS\_41723](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@JCMATTOS\_41723](https://community.f5.com/u/JCMATTOS_41723)\
**Post date:** [April 17, 2013, 9:39pm UTC](https://community.f5.com/t/parse-cookie-content-company-code-to-specific-pools/25481/3 "2013-04-17T21:39:34Z")

</div>

Thanks Kevin! I did verify it is an embedded value so this rule should work nicely then? I’ll test it out and see how it goes. Thx again!

---

<div class="post-metadata">

**Author:** ![JCMATTOS\_41723](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@JCMATTOS\_41723](https://community.f5.com/u/JCMATTOS_41723)\
**Post date:** [April 25, 2013, 5:06pm UTC](https://community.f5.com/t/parse-cookie-content-company-code-to-specific-pools/25481/4 "2013-04-25T17:06:23Z")

</div>

So after digging into this more. Looks like the initial client request doesn’t receive the cookie until successful login. Once the successful login the cookie is issued corresponding to a user to a unique company code. After testing this irule it seems to be inconsistent and not working properly, is it because of the cookie not being in the initial request? Is there a way to get this to work under these circumstances?

when HTTP\_REQUEST {

switch [HTTP::cookie “UserInfo”] {

“COMPANYID=A1” {

log local0. " matched COMPANYID=A1 in cookie UserInfo "

pool DEV-POOL1-80 }

“COMPANYID=B1” {

log local0. " matched COMPANYID=B1 in cookie UserInfo "

pool DEV-POOL2-80 }

“COMPANYID=C1” {

log local0. " matched COMPANYID=C1 in cookie UserInfo "

pool DEV-POOL3-80 }

}

}

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [April 26, 2013, 3:55am UTC](https://community.f5.com/t/parse-cookie-content-company-code-to-specific-pools/25481/5 "2013-04-26T03:55:22Z")

</div>

are you using oneconnect? if not, would it be possible to try?

sol9800: Using an iRule to load balance HTTP requests to multiple pools

> **[404 Page not found | BIG-IP Documentation](https://techdocs.f5.com/kb/en-us/solutions/public/9000/800/sol9800.html)**
>
> Usage information and technical documentation for BIG-IP and other related F5 products
