Forum Discussion

TFalk_342445's avatar
TFalk_342445
Icon for Nimbostratus rankNimbostratus
Apr 12, 2019

Check session variable fails

My apologies, I'm sure this is something stupidly simple that I'm just missing but I've been banging my head on this for a little while and all tests fail so far.

 

I want to check if a variable has been set already and if so, do nothing (in this part). And if it has not been set already, I am checking the incoming URL and picking up a specific part of the URL and set it to the variable.

 

I end up getting the variable set all the time, even when it's already set. I use this variable further down in the irule to redirect traffic according to this variable.

 

My code seems simple enough:

 

    when HTTP_REQUEST {
        if {[ info exists "ACCESS::session.custom.myvariable"] } {
        log local0. "Detecting myvariable variable, not doing anything."
        } else {
        set uri [string tolower [HTTP::uri]]
        set clientcode [string range [URI::path "$uri/" 2 2] 1 end-1]
        ACCESS::session data set session.custom.myvariable $clientcode
        log local0. "NOT detecting myvariable variable"
        log local0. "setting session variable to be $clientcode"
        }

    }

And what I end up getting in the log:

 

    `: NOT detecting myvariable variable
    : setting session variable to be clienttest
    : NOT detecting myvariable variable
    : setting session variable to be images

1 Reply

  • Hi

    You can try this...

    
    when ACCESS_SESSION_STARTED {
    ACCESS::session data set session.custom.myvariable ""
    }
    
    
    
    when HTTP_REQUEST { 
    
    if { ! [ACCESS::session data get session.custom.myvariable] equals "" ] } { 
        log local0. "Detecting myvariable variable, not doing anything." 
        } 
    else { 
        set uri [string tolower [HTTP::uri]] 
        set clientcode [string range [URI::path "$uri/" 2 2] 1 end-1] 
        
        ACCESS::session data set session.custom.myvariable $clientcode 
        log local0. "NOT detecting myvariable variable" 
        log local0. "setting session variable to be $clientcode" 
        
        }
    
    }