Forum Discussion

EduardoSousa's avatar
Icon for Altocumulus rankAltocumulus
Nov 03, 2022

Order of cookies

Hello there We have a problem where, at some times the order of cookies in the package are reversed, I wonder if there is an irule to reverse cookies, making the application cookie available before ...
  • Daniel_Wolf's avatar
    Nov 13, 2022

    Hi EduardoSousa,

    you somehow did not mention in which direction you want to reverse the cookie order. From BIG-IP to browser, or from BIG-IP to backend server. Hence I presumed you want to reverse the order from BIG-IP to backend server.

    Here is my iRule:


        # Remove Cookie by name
         HTTP::cookie remove "BIGCookie"
         # Reverse order of Cookies
         if { [HTTP::header exists Cookie] } {
            set cookie_rev {}
            set values [split " [HTTP::header Cookie]" ";"]
            set i [llength $values]
            while {$i} {lappend cookie_rev [lindex $values [incr i -1]]}
            set cookie_fini [join $cookie_rev ";"]
            HTTP::header replace Cookie "$cookie_fini"
            unset cookie_fini
            unset cookie_rev


    Browser to BIG-IP:

    BIG-IP to backend server
    BIGCookie is removed, order is reversed.

    Does this solve your issue?

    Note: The order of cookies usually should not be an issue. In my opinion reversing the order is not required. Maybe you can explain us, why you have this requirement?