cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.

Insert Pool Name into serverside HTTP Header

m_aremia
Nimbostratus
Nimbostratus

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!

 

6 REPLIES 6

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.

m_aremia
Nimbostratus
Nimbostratus

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.

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

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.

m_aremia
Nimbostratus
Nimbostratus

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?

HTTP:header insert <value> <name>

 

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

then in your irule, use something like

#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 !!!

m_aremia
Nimbostratus
Nimbostratus

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!