Forum Discussion

vlavergne_12825's avatar
vlavergne_12825
Historic F5 Account
Jul 28, 2005

Persist on the SET Cookie response from the server

Hi F5 Rulers !

I am currently having a customer with an iRule who want to persist on the SET COOKIE message contained in the server Response to the FIRST client REQUEST.

I would like to know if the HTTP::Cookie will intercept this Set Cookie from the Server ????

If it is failing, how can I work around it ?

Here is what my Rule look like so far :


rule SESSIONID_one {
  when HTTP_RESPONSE {
    if { [HTTP::cookie exists "SESSIONID"] } {
      set serv_cookie [persist lookup uie [HTTP::cookie "SESSIONID"] ]
      if { $serv_cookie != ""} {
        log local.0 "Cookie SESSIONID $serv_cookie already exists and   generated by [IP::server_add] for client [IP::client_addr]"
      }
      persist add uie [HTTP::cookie "PHPSESSID"]
  }
  when HTTP_REQUEST {
    if { [HTTP::cookie exists "SESSIONID"] } {
      set pl [persist lookup uie [HTTP::cookie "SESSIONID"] ]
      if { $pl ne "" } {
        pool HTTP member [lindex $pl 1] [lindex $pl 2]
      } else {
        pool HTTP
      }
    }
  }
}

Thanks for your response

Vincent

2 Replies

  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    Yes, in HTTP_RESPONSE, HTTP::cookie parses the Set-Cookie headers.

     

     

    I am confused though, because your rule seems to have some syntactic and semantic problems. First, there are unbalanced close braces in the HTTP_RESPONSE and second you do a persist add on PHPSESSID instead of SESSIONID. Other than your rule problems, your solution should work fine.
  • vlavergne_12825's avatar
    vlavergne_12825
    Historic F5 Account
    You are right but I hadn't any BIG-IP in front of me to verify !! That will be nice to have such an interface on devcentral to verify the rule syntax... However here is the final rule

    
    when HTTP_REQUEST {
       if { [HTTP::cookie exists "PHPSESSID"] } {
          set pl [persist lookup uie [HTTP::cookie "PHPSESSID"] ]
          if { $pl ne "" } {
             pool front member [lindex $pl 1] [lindex $pl 2]
          } else {
             log local.0 "Session ID [HTTP::cookie "PHPSESSID"] expired on the server for client [IP::client_addr]"
             pool front
          }
       }
    }
    when LB_FAILED {
       pool front
       log local.0 "LB Failed for client [IP::client_addr]"
       LB::reselect
    }
    when HTTP_RESPONSE {
       if { [HTTP::cookie exists "PHPSESSID"] } {
          set pl2 [persist lookup uie [HTTP::cookie "PHPSESSID"] ]
          if { $pl2 ne ""} {
             log local.0 "Existing Cookie PHPSESSID $pl2 generated by [IP::server_addr] and within persistance table 
    [lindex $pl2 1] [lindex $pl2 2] for client [IP::client_addr]"
          }
          persist add uie [HTTP::cookie "PHPSESSID"]
       }
    }

    Thanks for your help