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,
Have you tried removing the " " on your string trim?
Bhattman - 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'
So the .html still isn't being trimmed. - 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:
Manipulate a HTTP:path then continue to parse iRule
http://devcentral.f5.com/Default.aspx?tabid=53&view=topic&postid=813133&ptarget=813134
Aaron - 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" }
Now the trimming seems to be having as expected. Thanks. - 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] } }
Aaron - 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:
% string trimright /testtttt.html .html
/tes
If you want to remove .html from the URI, you could use string map:
% string map {.html ""} /testtttt.html
/testtttt
or for your iRule:
HTTP::path [string map {.html ""} [HTTP::path]]
Note that HTTP::path is the URI minus the query string. Assuming you only want to replace .html with nothing in the path this would be more precise.
Aaron - 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 }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
