Forum Discussion

BaltoStar_12467's avatar
Dec 02, 2014

BIG-IP : irule : ensure only a single instance of a cookie is present

F5 BIG-IP Virtual Edition v11.4.1 (Build 635.0) LTM on ESXi

I need to ensure that my response contains only a single instance of the the cookie

mycookie
and the value is set to 1

Will this work ?

when HTTP_RESPONSE {
  if { [HTTP::cookie exists mycookie] } {
    HTTP::cookie remove mycookie
  }
  HTTP::cookie insert name mycookie value 1
} 

My tests seem to indicate that the remove command only removes a single cookie

mycookie
-- but it's difficult testing.

Also : by default are all request cookies automatically included in the response ( assuming no irule manipulation of cookies )

  • I haven't tested this, so I'm not sure whether it will work properly, but you could use something like this below.

    if { [HTTP::cookie exists mycookie] } {
        while { [HTTP::cookie exists mycookie] } {
            HTTP::cookie remove mycookie
        }
        HTTP::cookie insert name mycookie value 1
    }
    
  • I need to ensure that my response contains only a single instance of the the cookie mycookie and the value is set to 1

     

    alternatively, you can just remove all the cookie named mycookie and then insert one with value 1 (i.e. no need to check first).