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

Filter by:
  • Solution
  • Technology
Answers

Insert custom Cookie on response with APM portal access resource

Hi All,

I have a situation where we need to insert a custom cookie (any name,value) for client browser to store. Need to set this cookie for a web application published using APM portal access resource.

I have tried various events in an iRule, tried HTTP_REQUEST and HTTP_RESPONSE combination and tried HTTP::header insert set-cookie as well as HTTP::cookie insert.

I also tried REWRITE_REQUEST_DONE to insert cookie on the client side.

I previously had to do the same on the server side which i did using ACCESS_ACL_ALLOWED successfully. I am wondering if this can be done now??

In LTM+APM mode this iRule and its correct variants work as expected i see the cookie being set and stored in browser but in portal access resource i only see set-cookie or cookie insert commands in logs but nothing in the browser.

Below is one version of the code i tried, please can someone help and advise? or had a previous experience with similar situation?

when HTTP_REQUEST { set isset [HTTP::cookie exists {MyCookie}]

}

when HTTP_RESPONSE { if {$isset == 0} { HTTP::cookie insert name MyCookie value One domain "mycompany.com" path "/"

foreach cookie [HTTP::cookie names] { HTTP::cookie secure $cookie enable }

} }

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hi

Try this

when REWRITE_REQUEST_DONE {
#Need something to signify that the right portal object is being called
    if {[HTTP::host] equals "www.example.com" } {
        set match 1
    }
}

when HTTP_RESPONSE_RELEASE {
    if { [info exists match] } {
        HTTP::cookie insert name MyCookie value "One; Secure;"
}

}

This code would need to be associated to the VIP hosting the APM profile that hosts the WebTop.

0
Comments on this Answer
Comment made 12-Apr-2018 by Ali Khan 57

Hi Iaine,

Thanks for your input. I did try the HTTP_RESPONSE_RELEASE and it worked. Only problem i have is we don't want to issue the cookie on every single response. I couldnt use it effectively with any other even if 'MyCookie' exists, if it does dont issue a cookie.

Any thoughts on that?

0
Comment made 12-Apr-2018 by iaine 820

So I'm guessing you mean that the cookie already exists on the HTTP request? If so, then you just need some extra logic to catch this, such as

when HTTP_REQUEST {
    if {[HTTP::cookie exists MyCookie]}{
    set mycookie 1
}

when REWRITE_REQUEST_DONE {
#Need something to signify that the right portal object is being called
    if {[HTTP::host] equals "www.example.com" } {
    if {![info exists mycookie]}{
            set match 1
       }
    }
}

when HTTP_RESPONSE_RELEASE {
    if { [info exists match] } {
        HTTP::cookie insert name MyCookie value "One; Secure;"
    }
}
0