Forum Discussion
Michael_Horvat_
Nimbostratus
Mar 28, 2007Appending URI
Does anyone know why the http::uri will not set to the uri variable?
set uri [HTTP::uri]
if { ! ([matchclass [string tolower [HTTP::uri]] contains $::WebFiles])
and ! ( $uri ends_with "/" ) } {
append uri "/" This is set properly
set HTTP::uri $uri This doesn't set
}
5 Replies
- JRahm
Admin
remove the set:if { ! ([matchclass [string tolower [HTTP::uri]] contains $::WebFiles]) and ! ( $uri ends_with "/" ) } { append uri "/" HTTP::uri $uri } - The problem is the set command. The "HTTP::uri" command comes in two flavors, one to retrieve the value (if used with no parameters) and one to set the value (if a value parameter is given).
With that being said, a simpler way would be to avoid the append on the temporary variable and just change it with the HTTP::uri command.set uri [HTTP::uri] if { ! ([matchclass [string tolower [HTTP::uri]] contains $::WebFiles]) and ! ( $uri ends_with "/" ) } { HTTP::uri "[HTTP::uri]/" }
-Joe - Michael_Horvat_
Nimbostratus
Both methods work. Thank you. - J___Alford_4002
Nimbostratus
I've been having the same difficulty. Tried the above sample code. Didn't work.
Slimmed it down and tried this:
when HTTP_REQUEST {
log local0. "in HTTP_REQUEST"
log local0. "Original: [HTTP::uri]."
set uri [HTTP::uri]
HTTP::uri "/prefix[HTTP::uri]/what_the/"
log local0. "After mapping: [HTTP::uri]"
}
The log local0. at the end doesn't show that it's been remapped. Why?
Thanks so much in advance,
Another Joe - That's due to an optimization in the caching of variables. The value of [HTTP::uri] is stored in a cache and when you re-assign the value with the "HTTP::uri value" command, the cached value for the [HTTP::uri] command is not updated. The URI will get modified, but the value returned from [HTTP::uri] is the original value. That issue has been around for a long time, maybe someday it'll get fixed.
In the meantime, if you want to verify your changes with logging, I'd suggest you use a temporary variable.when HTTP_REQUEST { log local0. "in HTTP_REQUEST" log local0. "Original: [HTTP::uri]." set uri "/prefix[HTTP::uri]/what_the/" log local0. "After mapping: $uri" HTTP::uri $uri }
You can verify this by looking at your backend webserver logs.
-Joe
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
