Forum Discussion
DNSgeek_90802
Nimbostratus
Dec 28, 2009modifying HTTP::uri not working?
I have an irule that needs to modify the URI of a request before it passes it to a pool of squid servers. What I have is:
when HTTP_REQUEST {
if { $::DEBUG }{
log "requri -> '[string tolower [HTTP::uri]]'"
}
HTTP::uri [string trimright [HTTP::uri] ".html"]
if { $::DEBUG }{
log "newuri -> '[string tolower [HTTP::uri]]'"
}
....
}
What I see in the logs is:
Dec 28 11:36:00 local/tmm info tmm[2790]: 01220002:6: Rule myrule : requri -> '/blah.html'
Dec 28 11:36:00 local/tmm info tmm[2790]: 01220002:6: Rule myrule : newuri -> '/blah.html'
So, The .html isn't being trimmed. Any idea why?
Thanks!
Tom
7 Replies
- The_Bhattman
Nimbostratus
Hi Tom, - DNSgeek_90802
Nimbostratus
Ok, I just tried that:when HTTP_REQUEST { if { $::DEBUG }{ log "requri -> [HTTP::uri]" } HTTP::uri [string trimright [HTTP::uri] .html ] if { $::DEBUG }{ log "newuri -> [HTTP::uri]"
Dec 28 13:24:14 local/tmm info tmm[2790]: 01220002:6: Rule myrule : requri -> '/blah.html' Dec 28 13:24:14 local/tmm info tmm[2790]: 01220002:6: Rule myrule : newuri -> '/blah.html'
- hoolio
Cirrostratus
Most of the HTTP:: command values are cached in the same event of the same priority. See this post for details and a few options: - DNSgeek_90802
Nimbostratus
So I changed my code to read:when HTTP_REQUEST { set myuri [HTTP::uri] if { $::DEBUG }{ log "requri -> $myuri" } set myuri [string trimright $myuri .html ] if { $::DEBUG }{ log "newuri -> $myuri" }
- hoolio
Cirrostratus
You haven't actually set the URI to the new value though. If you just want to log the update, you could use this:when RULE_INIT { set ::DEBUG 1 } when HTTP_REQUEST { if { $::DEBUG }{ log local0. "Original URI: [HTTP::uri] } HTTP::uri [string trimright [HTTP::uri] .html] } when HTTP_REQUEST priority 501 { This event runs after the prior HTTP_REQUEST event at the default priority of 500 Remove or comment out this event once done testing if { $::DEBUG }{ log local0. "Updated URI: [HTTP::uri] } }
- hoolio
Cirrostratus
Actually, string trimright won't work as you're expecting. It's not doing a replacement of .html--it's looking for any instance of any character in .html and removing it from the URI: - DNSgeek_90802
Nimbostratus
Ok, I changed it to be:when HTTP_REQUEST { set mypath [HTTP::path] if { $::DEBUG }{ log "reqpath -> $mypath" } set mypath [string map {.html ""} $mypath] if { $::DEBUG }{ log "newpath -> $mypath" } if { ! ($mypath ends_with "/") }{ set mypath $mypath/ if { $::DEBUG }{ log "apppath -> $mypath" } } HTTP::path $mypath pool A }
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