Forum Discussion
Adam_24063
Nimbostratus
Apr 15, 2007the scope of a variable.
Hello all.
I have some questions I couldn't find answers to in the docs or the archives.
What is the scope of non-global variables declared in an iRule?
Specifically, in examples i've seen situations where a variable is set in one event handler and then read in another within the same rule which leads me to believe there's a per connection context that is implicitly available.
For example, in the HTTPSession limit example, there is something like this:
when HTTP_REQUEST {
set need_cookie 0
}
when HTTP_RESPONSE {
if {$need_cookie == 1} { ... }
}
My most specific question, would this variable still be available in the CLIENT_CLOSE handler?
As a corollary, does this mean that if i have some HTML, (say for error pages) that i store in a variable that's defined in RULE_INIT that there's a copy of this hanging around for every connection ?
Now that I've laid it out in this posting I'm starting to think that the answer to all these questions is "yes", but any clarification (or pointers to docs) would be appreciated.
Thanks,
Radu
- Wes_98712
Nimbostratus
I think it depends on whether or not an irule, or multiple irules are assigned to a VS. If so, I believe the answer is yes, depending on what you are setting, if it's a simple variable declaration (e.g. set my_var 1) then that would be readable by any event. However if you set (set my_var [HTTP::host]) that variable would not be available for say a client accept event. - hoolio
Cirrostratus
I believe that variables declared in the RULE_INIT event are global by default. Variables declared in any other event with 'set my_local_var' are local and are accessible in every other event for that connection, but not accessible for any other connection. Variables declared in any other event with 'set ::my_global_var' are global and can be accessed in every other event and every other connection. - Adam_24063
Nimbostratus
Thanks for the info and the pointer.
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