# Insert Pool Name into serverside HTTP Header

**URL:** <https://community.f5.com/t/insert-pool-name-into-serverside-http-header/55013>\
**Category:** Technical Forums\
**Tags:** irules, ltm, application-delivery\
**Created:** [November 17, 2021, 7:49pm UTC](https://community.f5.com/t/insert-pool-name-into-serverside-http-header/55013 "2021-11-17T19:49:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![m\_aremia](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@m\_aremia](https://community.f5.com/u/m_aremia)\
**Post date:** [November 17, 2021, 7:49pm UTC](https://community.f5.com/t/insert-pool-name-into-serverside-http-header/55013/1 "2021-11-17T19:49:49Z")

</div>

Hello,

We currently use an irule to direct API calls to either a SOAP pool or REST pool based on URI Path. The Virtual Server has no Default pool configured. The way our current irule is configured is in the if statement where we are evaluating the path to determine what pool to send the api calls to, we are inserting the pool name to the header “manually.” We are not sure if this is the best way to do this or if there is an irule that can do this for us and can be attached to any Virtual Server where we want the pool name inserted in the HTTP path.

Example:

…

when HTTP\_Request {

if [string tolower [HTTP::path]] starts\_with “/xyz/1234”} {

HTTP::header insert “X-Pool” “REST\_Pool”

pool REST\_Pool

} elseif [string tolower [HTTP::path]] starts\_with “/abc/5678”} {

HTTP::header insert “X-Pool” “SOAP\_Pool”

pool SOAP\_Pool

} else {

HTTP::header insert “X-Pool” “Default\_Pool”

pool Default\_Pool

}

}

…

I have been reading about the “HTTP\_Request\_Send” functionality and we tested this in our Dev environment at the end of our irule by adding the following after the when HTTP\_Request.. removing the "HTTP::header insert “X-Pool” “Pool Name” command before the “pool Pool Name”.

when HTTP\_Request\_Send {

HTTP::header insert [LB::server pool]

}

This caused calls to fail so we reverted.

Basically we are wanting to create an irule that can be applied to any of our Virtual Servers where we control what pool the traffic is sent to using an irule to insert the pool name into the header without having to add the "HTTP::header insert “X-Pool” “REST\_Pool” command multiple times.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![jaikumar\_f5](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@jaikumar\_f5](https://community.f5.com/u/jaikumar_f5)\
**Post date:** [November 18, 2021, 6:41am UTC](https://community.f5.com/t/insert-pool-name-into-serverside-http-header/55013/2 "2021-11-18T06:41:39Z")

</div>

Is your requirement to send the traffic to a pool when it matches the path

(or)

Send the traffic to a pool when it matches the path along with the header being inserted.

I understand the part that you dont want to put multiple if else condition, this could be simplified with an Irule & datagroup combination or by other filters like extracting details from the path & framing the pool variable name automatically. Its just the requirement needs to be more specific. Can you please clarify this.

---

<div class="post-metadata">

**Author:** ![m\_aremia](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@m\_aremia](https://community.f5.com/u/m_aremia)\
**Post date:** [November 18, 2021, 12:57pm UTC](https://community.f5.com/t/insert-pool-name-into-serverside-http-header/55013/3 "2021-11-18T12:57:22Z")

</div>

Yes our intention is to send traffic to a pool that matches a specific path. So we do have different if else statements to handle that logic and this is acceptable for us. We are looking for a better way to use an irule to insert the pool name to the header after the pool has been selected. Currently we are doing that with ‘HTTP::header insert’ after it matches the HTTP path and before the traffic is sent to the pool.

The idea is to have an irule that can do this separate from our irule used to send traffic to the different pools after a path is matched. That way we can use this across multiple Virtual Servers where needed instead of having to update the other irules with the HTTP::header insert.

---

<div class="post-metadata">

**Author:** ![jaikumar\_f5](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@jaikumar\_f5](https://community.f5.com/u/jaikumar_f5)\
**Post date:** [November 18, 2021, 1:14pm UTC](https://community.f5.com/t/insert-pool-name-into-serverside-http-header/55013/4 "2021-11-18T13:14:00Z")

</div>

Understood. But do the path name & pool name have something in common ? because from your example, it clearly doesn’t match any pattern.

If it was something like.

URI - “/xyz/1234” --\> Send traffic to Pool\_xyz or Pool\_1234

URI - “/abc/5678” --\> Send traffic to Pool\_abc or Pool\_5678

We can simply extract xyz or abc or 1234 or 5678 and set it on a variable.

Then use

```tcl
set poolname Pool_$extractedvalue

```

You see what I’m telling, we can auto populate it, if its matches a pattern. That way we dont have to hardcore it.

If these don’t match a pattern, the way i see it is to build a datagroup with path as key & poolname as value pair. Build a class match condition & send the traffic to pool as well insert header with the value. You can use this datagroup across multiple other irules too.

---

<div class="post-metadata">

**Author:** ![m\_aremia](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@m\_aremia](https://community.f5.com/u/m_aremia)\
**Post date:** [November 18, 2021, 1:39pm UTC](https://community.f5.com/t/insert-pool-name-into-serverside-http-header/55013/5 "2021-11-18T13:39:55Z")

</div>

There is no real pattern to the path and pool name and being so your suggestion would to use a datagroup, a class match condition to send the traffic to the pool with the following?

```tcl
HTTP:header insert <value> <name>

```

---

<div class="post-metadata">

**Author:** ![jaikumar\_f5](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@jaikumar\_f5](https://community.f5.com/u/jaikumar_f5)\
**Post date:** [November 18, 2021, 2:33pm UTC](https://community.f5.com/t/insert-pool-name-into-serverside-http-header/55013/6 "2021-11-18T14:33:18Z")

</div>

Create your datagroup with URI as record and pool name as value.

then in your irule, use something like

```tcl
#take http uri
set httpuri [string tolower [HTTP::uri]]
 
#Compare against Datagroup and pull out the pool name
set poolname [class match -value $httpuri starts_with DATAGROUP_NAME]
 
#To insert the poolname as header
HTTP::header insert "X-Pool" $poolname
 
#To send the traffic to the respective pool
pool $poolname

```

Hope you got the point !!!

---

<div class="post-metadata">

**Author:** ![m\_aremia](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@m\_aremia](https://community.f5.com/u/m_aremia)\
**Post date:** [November 18, 2021, 2:40pm UTC](https://community.f5.com/t/insert-pool-name-into-serverside-http-header/55013/7 "2021-11-18T14:40:47Z")

</div>

Thanks for your help. I will take this back to my team and test this out. I will provide an update with the results. Have a great one!
