Forum Discussion
Is it possible to use the following Irule syntac with TCL in a policy ?
I've setup some code in an Irule .
This concerns a code that will take the URI, within this uri, search for first directory in the path and put it tolower before sending it to the server.
set uri [HTTP::uri]
I need to replace the first directory of the URI (ie: "/APPLICATION/dir1/DIR2/index.html") to lowercase /application/dir1/DIR2/index.html ( the rest of the URI must stay intact, only /Application/ part must be set to lowercase.
Thanks in advance.
Regards
Lemaire_Frédéri I don't see any issue with the block of code if it were added to an iRule with the correct event. I would convert all your policy rules to one iRule though instead of using both simultaniously because it's much easier to go to one location rather than multiple when troubleshooting.
- JRahmAdmin
HI Lemaire_Frédéri , conditions in policies don't accept Tcl expressions, only actions. If we could land on a single expression to accomplish this it might be possible, but anything requiring anything more than a cached value lookup in a policy sends me to an iRule outright by preference...your mileage may vary. To your block of code, you can simplify that to not set any variables at all (not as readable), and if you're always going to rewrite if it "isn't" lowercase, then you don't really need the condition and can just rewrite always, right? Anway...IF that's the case for this particular virtual server, THEN, you might yet be able to use a policy with this:
rewrite_first_path_segment { actions { 0 { http-uri replace value "tcl:[string map [list [getfield [HTTP::uri] / 2] [string tolower [getfield [HTTP::uri] / 2]]] [HTTP::uri]]" } } ordinal 5 }
Again, I'd go the iRule route here, but you can investigate from here with the policy. A couple other solution options I was noodling on for fun:
# option 1 - close to your solution set pathobj [getfield [HTTP::uri] "/" 2] if { ![string equal $pathobj [string tolower $pathobj]] } { HTTP::uri [string map [list $pathobj [string tolower $pathobj]] [HTTP::uri]] } # option 2 - regex rewrite if { [regexp {^(/[^/]+)(/.*)?$} [HTTP::uri] -> pathobj remaining_uri] } { HTTP::uri [join [list [string tolower $pathobj] $remaining_uri] "/"] }
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