For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

iRule to take cookie from HTTP Response into HTTP Request via table

Sanitized version of an iRule. It’s main function is to take a cookie from a HTTP Response; put the value into a table and then insert into a HTTP request.

The switch statement section has been stripped right back. So please re-construct to your own needs.

The iRule contains some failsafe testing table look-ups and logging.

when HTTP_REQUEST {
#
set requestjcookie "jcookie"
set dailycookie [table lookup -subtable "change-me-cookie" $requestjcookie]
#
#log local0. "CHANGE-ME: HTTP Request Cookie $dailycookie"
#
switch -glob [HTTP::path] {

Note: Section stripped back. Please re-create as per  the need

HTTP::cookie remove "JSESSIONID"
HTTP::cookie insert name "JSESSIONID" value $dailycookie

}
}

when HTTP_RESPONSE {
if { [HTTP::header exists "Set-cookie" ] } {
set cookies [HTTP::cookie names]
foreach cookie $cookies {
set cookie_value [HTTP::cookie $cookie]
# log local0. "CHANGE-ME: $cookie_value"
set responsejcookie "jcookie"
table set -subtable "change-me-cookie" $responsejcookie $cookie_value indef
table replace -subtable "change-me-cookie" $responsejcookie $cookie_value indef
set viewtb [table lookup -subtable "change-me-cookie" $responsejcookie]
# log local0. "CHANGE-ME: Listing $viewtb"
}
}
}

Published May 11, 2023
Version 1.0

1 Comment

  • Thanks for the contribution matfreem.
    Quick note on your code contribution.

    • If you choose the </> button in the editor toolbar.
    • Select language = tcl 
    • paste your content in.
    when HTTP_RESPONSE {
    if { [HTTP::header exists "Set-cookie" ] } {
    set cookies [HTTP::cookie names]

    It'll come out with some nice color-coded syntax.

    (NOTE: there is a bug adding spaces above and below the codeblocks.
    While that is being worked on in the background - you can alleviate the issue by leaving (or re-adding) this wrapper div in your content using the HTML button.

    <div class="lia-message-template-content-zone">
    ...all your stuff in here...
    </div>