Forum Discussion

Osama_Friejeh_6's avatar
Osama_Friejeh_6
Historic F5 Account
Mar 11, 2008

add cookie in http response after 302 redirect

Hi,

 

 

i am load balancing three web servers that require authentication and persistence. all work fine until certain links return a 302 redirect. the connection is load balanced to a new member and the user has to authenticate again.

 

 

i am using cookie insert as a persistence profile.oneconnect is enabled. looking at the cookies sent by the BIG-IP in response to the new URL, i cannot see the BIG-IP cookie sent to the browser, i think this is because the UL has changed.

 

 

i am looking for assistance on an iRule that would extract the BIG-IP inserted cookie and add to the http response of the 302 redirect.

 

 

something like this:

 

 

when HTTP_RESPONSE {

 

if { [HTTP::status] == 302 } {

 

...

 

commands to extract BIG-IP inserted Cookie

 

HTTP::cookie insert ...insert cookie with same value.

 

 

  • Hi,

     

     

    Could it be that your 302 redirect on another domain ?

     

     

    If yes, you can update the domain data of the BIGIP cookie:

     

     

    when HTTP_RESPONSE {

     

     

    use this domain to set the domain attribute on the

     

    BIG-IP persistence cookie

     

    set my_domain ".example.com"

     

    set my_pool "poolA"

     

     

    loop through each of the cookies in the response

     

    if {[HTTP::cookie count] > 0 } {

     

    foreach aCookie [HTTP::cookie names] {

     

    if the current cookie matches the format for the persistence cookie, modify it

     

    if { $aCookie == BIGipServer$my_pool" } {

     

    set the domain attribute on the persistence cookie

     

    HTTP::cookie domain $aCookie $my_domain

     

    }

     

    }

     

    }

     

    }

     

  • Osama_Friejeh_6's avatar
    Osama_Friejeh_6
    Historic F5 Account
    thanks for the super fast response.

     

     

    actually it is the same domain

     

     

    here is the redirect:

     

     

    http://domain:7777/edugate/faces/__ADFv__?_afPfm=1&_t=fred&_vir=/student/reps.jspx&loc=ar&_minWidth=800&_minHeight=600&_rtrnId=0

     

     

    Redirect to http://domain:7777/edugate/student/reps/form5d41a113130d5f0a9105cd7b643299d1ffd275ed2bc2a.pdf
  • Hi,

     

     

    it is strange. The BIGIP should insert the cookie persistence even on redirect ...

     

     

    i did a test and i confirmed it:

     

     

    GET / HTTP/1.1

     

    Host: www.google.com

     

    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12

     

    Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

     

    Accept-Language: en-gb,en;q=0.5

     

    Accept-Encoding: gzip,deflate

     

    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

     

    Keep-Alive: 300

     

    Connection: keep-alive

     

    Cookie: PREF=ID=b72527e22a544d83:TM=1204207469:LM=1205017595:GM=1:S=f1MJLoItaQlNuQcj

     

     

    HTTP/1.x 302 Found

     

    Location: http://www.google.fr/

     

    Cache-Control: private

     

    Content-Type: text/html

     

    Server: gws

     

    Content-Length: 218

     

    Date: Tue, 11 Mar 2008 12:44:39 GMT

     

    Set-Cookie: BIGipServerPool_Google=1753699793.20480.0000; path=/

     

     

    I think you may have an issue where the cookie is not stored correctly within your browser because the hostname of the website is not a FQDN. If you want to check the bigip insert correctly its persistence cookie within the http redirect you can do the following :

     

     

    Could you try something like this:

     

     

    when HTTP_REQUEST {

     

    set request [HTTP::request]

     

    }

     

     

    when HTTP_RESPONSE {

     

    loop through each of the cookies in the response

     

    if {[HTTP::cookie count] > 0 } {

     

    foreach aCookie [HTTP::cookie names] {

     

    if the current cookie matches the format for the persistence cookie, modify it

     

    if { $aCookie contains "BIGipServer"} {

     

    set the domain attribute on the persistence cookie

     

    log local0. "HTTP request: $resquest"

     

    log local0. "HTTP cookie: [HTTP::cookie $aCookie]"

     

    }

     

    }

     

    }

     

    }

     

     

    If you changed the cookie persistence name, please update the line $aCookie contains "BIGipServer"

     

     

    Once this iRule is assigned to your VS, check your /var/log/ltm to see if it is inserted within your expected answer