Forum Discussion
Juha__Ranta_106
Nimbostratus
Aug 17, 2005Need help with Tcl [string first "/foo/" $var] ...
Hello,
I need to find first occurance of string "/foo/" in HTTP::uri
and replace it with "/foobar/".
I have the following 'when HTTP_REQUEST' event in my iRule:
when HTTP_REQUEST {
set uri [HTTP::uri]
log LOCAL0.debug "> URI='$uri'";
set foo "/foo/";
set idx1 [string first $foo $uri];
if { $idx1 >= 0 } {
log LOCAL0.debug " - '$uri'.firstIndexOf('$foo') = $idx1";
set idx2 [expr $idx1 + [string length $foo] - 1];
set uri [string replace $uri $idx1 $idx2 "/foobar/"];
HTTP::uri $uri
}
log LOCAL0.debug "< URI='$uri'";
}
Ok, this seems to work fine, but I have detected that..
[string first "/foo/" $uri]
...also returns value >= 0 when $uri has value like:
"/something_fishy/foo?"
"/is_going_on/fooX"
Here is a part of my '/var/log/ltm' log that demonstrates what goes wrong.
Aug 17 11:09:22 tmm tmm[700]: Rule foo : > URI='/this_works_fine/foo/something'
Aug 17 11:09:22 tmm tmm[700]: Rule foo : - '/this_works_fine/foo/something'.firstIndexOf('/foo/') = 16
Aug 17 11:09:22 tmm tmm[700]: Rule foo : < URI='/this_works_fine/foobar/something'
Aug 17 11:09:40 tmm tmm[700]: Rule foo : > URI='/this_does_not_work_correctly/foo?'
Aug 17 11:09:40 tmm tmm[700]: Rule foo : - '/this_does_not_work_correctly/foo?'.firstIndexOf('/foo/') = 30
Aug 17 11:09:40 tmm tmm[700]: Rule foo : < URI='/this_does_not_work_correctly//foobar/'
Aug 17 11:10:12 tmm tmm[700]: Rule foo : > URI='/this_does_not_work_correctly_either/fooX'
Aug 17 11:10:12 tmm tmm[700]: Rule foo : - '/this_does_not_work_correctly_either/fooX'.firstIndexOf('/foo/') = 37
Aug 17 11:10:12 tmm tmm[700]: Rule foo : < URI='/this_does_not_work_correctly_either//foobar/'
Aug 17 11:11:20 tmm tmm[700]: Rule foo : > URI='/now_it_works_again/foo?param=no_urirewrite_should_occur'
Aug 17 11:11:20 tmm tmm[700]: Rule foo : < URI='/now_it_works_again/foo?param=no_urirewrite_should_occur'
Aug 17 11:11:34 tmm tmm[700]: Rule foo : > URI='/now_it_works_again/foo/?param=this_is_ok'
Aug 17 11:11:34 tmm tmm[700]: Rule foo : - '/now_it_works_again/foo/?param=this_is_ok'.firstIndexOf('/foo/') = 19
Aug 17 11:11:34 tmm tmm[700]: Rule foo : < URI='/now_it_works_again/foobar/?param=this_is_ok'
It seems to me, that 'string first' function is broken in bigip
Tcl runtime, but is there some other way of doing this ?
PS: I'm running bigip version 9.0.5
- drteeth_127330Historic F5 AccountWe are investigating this problem. In the meantime, you can use this alternate implementation. Good luck!
regsub "/foo/" $uri "/foobar/" uri
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