Forum Discussion

myself_85560's avatar
myself_85560
Icon for Nimbostratus rankNimbostratus
Jun 01, 2016

LB decisions matching the headers

Hi, We have a custom written application that is being hosted on multiple servers behind the LTM. It does not use cookies rather a variety of unique http headers. I need to use these unique headers to make load balancing decisions.

 

Below first set of headers that should hit the pool_1

 

TEST/Rumba/mountainisred@4

 

TEST/Rumba/mountainisblue@2

 

TEST/Rumba/mountainisorange@2

 

TEST/Rumba/mountainisgreen@2

 

Below second set of headers that should hit the pool_2

 

TEST/Rumba/mountainispink@2

 

TEST/Rumba/mountainisgray@2

 

TEST/Rumba/mountainiswhite@2

 

TEST/Rumba/mountainisblack@2

 

Traffic with none of the above headers to hit a default_pool pool_3

 

Here is my iRule:

 

when HTTP_REQUEST { if { [HTTP::header value mountainisred@4} {

 

pool pool_1 } else {

 

pool main_pool

 

} }

 

Your response is much appreciated.

 

Thanks

 

  • Hi,

    I would recommend the modified irule below, changed second if by elseif. Otherwise, If you match the first if you also match the else and you will have a tcl error and a tcp reset on thz client side :

    when HTTP_REQUEST {
    if { [class match [HTTP::header "online.protocol.remote.contenttype"] equals header_value_1] } {
            pool_1
        }
    elseif { [class match [HTTP::header "online.protocol.remote.contenttype"] equals header_value_2] } {
            pool_2
        } 
        else {
            pool_3
        }
       }
    
  • Hi,

    You can take the below irule as example, I assumed that you were talking about uri not headers but correct me if I'm wrong :

    when HTTP_REQUEST {
        switch -glob [HTTP::uri] {
            "*TEST/Rumba/mountainisred@4*" -
            "*TEST/Rumba/mountainisblue@2*" -
            "*TEST/Rumba/mountainisorange@2*" -
            "*TEST/Rumba/mountainisgreen@2*" {
                pool_1
            }
            "*TEST/Rumba/mountainispink@2*" -
            "*TEST/Rumba/mountainisgray@2*" -
            "*TEST/Rumba/mountainiswhite@2*" -
            "*TEST/Rumba/mountainisblack@2*" {
                pool_2
            }
            default {
                pool_3
            }
    
        }
    }
    
    • myself_85560's avatar
      myself_85560
      Icon for Nimbostratus rankNimbostratus
      Thanks Yann for your quick response. Nope. Its not the uri but headers. I am sure. I have seen the headers. The headers has 3 or 4 lines of unique strings. I took out one of them, that are widely looks a similar type across all the headers. Does that makes any difference if it is a POST rather than a GET.
  • Hi,

    You can take the below irule as example, I assumed that you were talking about uri not headers but correct me if I'm wrong :

    when HTTP_REQUEST {
        switch -glob [HTTP::uri] {
            "*TEST/Rumba/mountainisred@4*" -
            "*TEST/Rumba/mountainisblue@2*" -
            "*TEST/Rumba/mountainisorange@2*" -
            "*TEST/Rumba/mountainisgreen@2*" {
                pool_1
            }
            "*TEST/Rumba/mountainispink@2*" -
            "*TEST/Rumba/mountainisgray@2*" -
            "*TEST/Rumba/mountainiswhite@2*" -
            "*TEST/Rumba/mountainisblack@2*" {
                pool_2
            }
            default {
                pool_3
            }
    
        }
    }
    
    • myself_85560's avatar
      myself_85560
      Icon for Nimbostratus rankNimbostratus
      Thanks Yann for your quick response. Nope. Its not the uri but headers. I am sure. I have seen the headers. The headers has 3 or 4 lines of unique strings. I took out one of them, that are widely looks a similar type across all the headers. Does that makes any difference if it is a POST rather than a GET.
  • Hi Yann,

     

    One of the header looks something like this.

     

    POST /online/vendorlink/protocol/3 HTTP/1.1

     

    Content-Type: application/x-onl-pki-smime

     

    online.protocol.remote.contenttype: TEST/Rumba/mountainisred@4

     

    Cache-Control: no-cache

     

    Pragma: no-cache

     

    User-Agent: Java/1.7.0_25

     

    Host: host1.abc.com

     

    Accept: text/html, image/gif, image/jpeg, *; q=.2, /; q=.2

     

    Connection: keep-alive

     

    Content-Length: 5836

     

    thanks

     

  • Hi,

     

    So you can change the [HTTP::uri] command in the switch by [HTTP::header "online.protocol.remote.contenttype"]

     

    • myself_85560's avatar
      myself_85560
      Icon for Nimbostratus rankNimbostratus
      Will this one work as well? [HTTP::header "mountainisred@4"] Please advise. thanks
    • myself_85560's avatar
      myself_85560
      Icon for Nimbostratus rankNimbostratus
      Hi Yann, ignore me. Yes ,it is the name and value match. I got it. thanks
  • Hi,

     

    So you can change the [HTTP::uri] command in the switch by [HTTP::header "online.protocol.remote.contenttype"]

     

    • myself_85560's avatar
      myself_85560
      Icon for Nimbostratus rankNimbostratus
      Will this one work as well? [HTTP::header "mountainisred@4"] Please advise. thanks
    • myself_85560's avatar
      myself_85560
      Icon for Nimbostratus rankNimbostratus
      Hi Yann, ignore me. Yes ,it is the name and value match. I got it. thanks
  • Hi,

     

    Can we supply or pass the header values from a txt file, into the iRule. The txt file to contain all the header values, tab limited etc. using internal data-group? and be made available to the iRules?

     

    Please advise how I can achieve it.

     

    thanks

     

    • Yann_Desmarest's avatar
      Yann_Desmarest
      Icon for Cirrus rankCirrus
      Hi, you can pass a datagroup file by using the following command 'class match [HTTP::header "online.protocol.remote.contenttype"] equals header_value'. header_value is the name of your datagroup.
    • Yann_Desmarest's avatar
      Yann_Desmarest
      Icon for Cirrus rankCirrus
      But using datagroup, you can't use the switch anymore, you have to use if instead.
  • Hi Yann,

    See below. I came out with an iRule. Would this be OK. Please respond. Much appriciated.

    These are string data-groups; header_value_1 & header_value_2

    when HTTP_REQUEST {
    if { [class match [HTTP::header "online.protocol.remote.contenttype"] equals header_value_1] } {
            pool_1
        }
    if { [class match [HTTP::header "online.protocol.remote.contenttype"] equals header_value_2] } {
            pool_2
        } 
        else {
            pool_3
        }
       }
    
  • Hi,

    I would recommend the modified irule below, changed second if by elseif. Otherwise, If you match the first if you also match the else and you will have a tcl error and a tcp reset on thz client side :

    when HTTP_REQUEST {
    if { [class match [HTTP::header "online.protocol.remote.contenttype"] equals header_value_1] } {
            pool_1
        }
    elseif { [class match [HTTP::header "online.protocol.remote.contenttype"] equals header_value_2] } {
            pool_2
        } 
        else {
            pool_3
        }
       }
    
  • Hi,

    I would recommend the modified irule below, changed second if by elseif. Otherwise, If you match the first if you also match the else and you will have a tcl error and a tcp reset on thz client side :

    when HTTP_REQUEST {
    if { [class match [HTTP::header "online.protocol.remote.contenttype"] equals header_value_1] } {
            pool_1
        }
    elseif { [class match [HTTP::header "online.protocol.remote.contenttype"] equals header_value_2] } {
            pool_2
        } 
        else {
            pool_3
        }
       }