Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

Set cookie in 10% of traffic

Hi,

I'm looking for a way to set a cookie on 10% of my web traffic. How can it be implemented in an irule?

Thanks!

0
Rate this Question
Comments on this Question
Comment made 1 month ago by Daniel W. 275

This example should help you: https://devcentral.f5.com/codeshare/ratio-load-balancing-using-rand-function

Just use if { rand() < 0.1 } { ...

2

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

It will be good if you throw some more light here. I tried to prepare irule based on above conditions. you can edit & apply based on condition.

when HTTP_REQUEST {
if { rand() < 0.1 } {
    if { [HTTP::cookie exists "old-cookie-name"] } {
  # Insert a new cookie with the new name and old cookie's value
    HTTP::cookie insert name "new-cookie-name" value [HTTP::cookie value "old-cookie-name"]
  # Remove the old cookie
  HTTP::cookie remove "old-cookie-name" }
    }
}
0