Forum Discussion
smp_86112
Cirrostratus
May 04, 2010v10 - local vs. global vars
Trying to wrap my mind around how this variable scope works. I have a simple iRule I'm testing with:
when HTTP_REQUEST {
global client_local [TCP::local_port clientside]
if...
hoolio
Cirrostratus
May 04, 2010Hi SMP,
global my_var, set ::my_var, and any variable set in RULE_INIT will be global and accessible across all connections to the VIP. If you want to set a variable which is only accessible for one TCP connection (from any iRule on the VIP), you can use a local variable.
when CLIENT_ACCEPTED {
switch [TCP::local_port clientside] {
443 {
set protocol "https"
}
default {
set protocol "http"
}
}
log local0. "$protocol"
}
As the port can't change over the course of the TCP connection, I've moved your code to the CLIENT_ACCEPTED event so it only runs once per connection. You can then reference the $protocol variable in any iRule on the same VIP. If you're referencing the $protocol variable in other rules in the same event it's set in, make sure this iRule is placed before any other iRules on the VIP or explicitly set priority on this iRule so it runs before them.
Aaron
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects