Forum Discussion

Sam10's avatar
Sam10
Icon for Altostratus rankAltostratus
Oct 17, 2019

cookie persistence with an irule

We are setting up a virtula server on f5 , and need to balance traffic such a way where client passes a cookie value in the header based on the cookie value traffic need to be passed to a specific node. how can i get this achieved with an irule.

such a cookie value of "cookie 1----- node1"

"cookie2 ----- node 2"

"cookie 3------- node 3"

"cookie 4------- node4"

 

If there is no cookie value inserted then traffic need to be assigned to default pool.

2 Replies

  • Hi Sam10,

    Can you try this iRule?

    when HTTP_REQUEST {
    	if { [HTTP::cookie exists "cookieName"] } {
    		set cookieValue [HTTP::cookie value "cookieName"]
    		# log local0. "CookieValue: $cookieValue"
    		
    		switch -glob $cookieValue {
    			"cookie1" { node node1 }
    			"cookie2" { node node2 }
    			"cookie3" { node node3 }
    			"cookie4" { node node4 }
    		}
    	}
    	else {
    		pool pool_default
    	}
    }
    • Sam10's avatar
      Sam10
      Icon for Altostratus rankAltostratus

      thanks for your response, but are we looking into the cookie value in the header and if the value is cookie1 then sending traffic to node1, vice versa

      if { [HTTP::cookie exists "cookieName"] } what will be my cookieName as the value keeps changing so