Forum Discussion
kendalladkins_5
Nov 09, 2007Nimbostratus
Variable Scope & Lifetime
I am relatively new to iRule development and I need a little help understanding variable scope. My main objective is to understand how I pass values from the HTTP_REQUEST event to the HTTP_RESPONSE event for a single HTTP handshake. Here is an example:
when HTTP_REQUEST {
if {[TCP::local_port] == 80} {
set protocol "http"
} else {
set protocol "https"
}
set url "$protocol://[HTTP::host][HTTP::uri]"
}
when HTTP_RESPONSE {
HTTP::respond 200 content "$url"
}
Here are some questions I have:
1. Will the above iRule always return the client's original request URL?
2. What is the scope and lifetime of a local variable?
3. What is the scope and lifetime of a global variable?
4. Should I use the global command to declare globals instead of set ::varname? There is significant tcl documentation that implies that this performs better.
5. Is there any documentation on this?
Thanks
- Deb_Allen_18Historic F5 Accountdone
- Nick_Lawes_6698NimbostratusTaking this one step further, I've just installed a working iRule onto a bigger machine that has 4 tmm's, and it gets a but cranky. Presumably with this setup "global" variables are specific to each instance of the tcl interpreter, rather than the logical iRule, making 4 sets of globals...
- Deb_Allen_18Historic F5 AccountThat's correct, global variables are not shared across TMMs, rather 1 is maintained per TMM, separately.
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