Forum Discussion
Calling procs dynamically
I have successfully tested calling procs like this:
eval call [string tolower {HTTP::host}]::procName
However, I'm trying to stop using HTTP::host directly because the TCL checker freaks completely out thinking things are out of context when this type of call is defined outside of an event. I understand that and am trying to work around it by using
set host [string tolower [HTTP::host]]
and all kinds of other dumbness. I'm not expanding/unpacking the variable properly. All of the following fail:
call $host::procName $arg1 $arg2
eval call [string tolower {$host}]::procName $arg1 $arg2
eval [call {$host}]::procName $arg1 $arg2
However, as expected, using
actualValueInHostVar::procname $arg1 $arg2
works perfectly. I know that someone out there can set me straight on this.
Thanks.
- Josh_B_152229Nimbostratus
Much progress has been made. What I found is incredibly frustrating, but I assume it's because I was (somehow) "doing it wrong."
The goal was to dynamically call a proc named
inside a rule that was named the same as an expectedhttp_request
(something that would resolve to the virtual server and be handled by the rule). I have had much success with something very similar before where I set a variable based on a datagroup lookup and performed something simlar to[HTTP::host]
.eval call [$variable]::procName
As indicated above, the variable substitution must not act how I think it should and the following not only does not work, but also crashes TMM on 11.6.0 HF3:
set host [string tolower [HTTP::host]] set uri [string tolower [HTTP::uri]] eval call [string tolower {HTTP::host}]::http_request $host $uri
My initial testing shows that defining the entire proc to call as a
works, but using variable substitution (string
instead of$host
) when setting[string tolower [HTTP::host]]
below doesn't work. Not much testing has been done, yet, but the following appears to behave as I expect it:http_request
set host [string tolower [HTTP::host]] set uri [string tolower [HTTP::uri]] set http_request "[string tolower [HTTP::host]]::http_request" eval call $http_request $host $uri
- Josh_B_152229NimbostratusUpdate: The last line also works when passing TCL words instead of the variables like so: `eval call $http_request [HTTP::host] [HTTP::uri]` As "expected" as that is, it's exciting to me because I have seen so much unexpected behavior with variable substitution lately.
Recent Discussions
Related Content
* 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