Forum Discussion

martin_58353's avatar
Oct 11, 2017

transfer values between sessions

Hello, I need transfer value between different client requests (sessions?). First I used cookie (e.g. cookie name "cookie-a"), but value of this cookie should be not visible on client site. I have other cookie (e.g. "cookie-b") based on it I can pair bot connections.

 

In first connection I need store value (before stored in cookie-a) on big-ip. In second connection I need read this value.

 

I can use session or table, but based on documentation it's not clear for me. https://devcentral.f5.com/articles/the101-irules-101-variables https://devcentral.f5.com/wiki/iRules.session.ashx https://devcentral.f5.com/wiki/iRules.table.ashx

 

what is better choose - session or table (I'm not familiar with both of them). where are more details about for session?

 

 

I have two apps (/server1.txt and /server2.txt) between this I need transfer value. In my lab I have three clients (different browsers on the same pc - FF, IE, EDGE). when I try to use 'session' (see code below) it is working but I'm not sure if this is correct code.

 

exists any better solution of this?

 

here is my code:

 

when HTTP_REQUEST {
    switch [HTTP::uri] {
      "/server1.txt" { 
         random value for client session (based on cookie 'cookiename')
        set uid [clock seconds] 
        session add sticky cookiename $uid 30
        if { [HTTP::cookie exists cookiename] } {
          session add simple [HTTP::cookie value cookiename] $uid 30 
        }
      }
      "/server2.txt" { 
         read of value in another client connection (http request)
         it is working but I'm not sure if it's best solution
        if { [HTTP::cookie exists cookiename] } {
          set value [session lookup simple [HTTP::cookie value cookiename]]
        } else { set value "undefined" }
        HTTP::respond 200 content "this is uid='$value'" "content-type" "text/plain" "Connection" "close"
        event HTTP_REQUEST disable
      }
}

martin

 

1 Reply

  • https://devcentral.f5.com/wiki/irules.table.ashx

     

    "The table command (like the session command) is a way to access the session table. The table command is a superset of the session command, with improved syntax for general purpose use. Please see the table command article series for detailed information on its use."

     

    I had an idea that table command was deprecated, but I can confirm that. Anyway, they do the same work.

     

    iRule looks ok, and using session table is the correct option. Just a small change, you dont need the event command.

     

    https://devcentral.f5.com/wiki/irules.http__respond.ashx

     

    "The BIG-IP will send the response as soon as the current iRule event completes, so you cannot alter the response in other HTTP iRule events."