Forum Discussion

D_T's avatar
D_T
Icon for Cirrus rankCirrus
Feb 10, 2023

Copy Cookie Header with new Header Name

How could I go about copying a cookie header into another cookie name. I don't want to rename but make a duplicate with a new name. I am not finding too much on this particular topic. Thank you!

3 Replies

  • D_T I believe what you are trying to do is the following which will search for the cookie and then insert a new cookie with the same value as the old cookie and the header will have both the old and new cookie in it.

    when HTTP_REQUEST {
    
        if {[HTTP::header exists "old-cookie-name"]}{
            HTTP::cookie insert name "new-cookie-name" value [HTTP::cookie value "old-cookie-name"]
        }
    
    }
    • D_T's avatar
      D_T
      Icon for Cirrus rankCirrus

      This unfortunately does not appear to be doing the trick. Does this only work with response cookies?

      • D_T This would be on the request but you could try to change it to the response as well which would require replacing "HTTP_REQUEST" with "HTTP_RESPONSE" in the above iRule or you can combine them together. Please keep in mind that the values with "old-cookie-name" and "new-cookie-name" should be replaced with the cookie you are searching for, old-cookie-name and the new cookie name which is new-cookie-name in the example.

        when HTTP_REQUEST priority 500 {
        
            if {[HTTP::header exists "old-cookie-name"]}{
                HTTP::cookie insert name "new-cookie-name" value [HTTP::cookie value "old-cookie-name"]
            }
        
        }
        
        when HTTP_RESPONSE priority 500 {
        
            if {[HTTP::header exists "old-cookie-name"]}{
                HTTP::cookie insert name "new-cookie-name" value [HTTP::cookie value "old-cookie-name"]
            }
        
        }