Forum Discussion
skunk69_85565
Nov 06, 2007Historic F5 Account
need to insert new info into HTTP query or uri
Hi everyone,
I need some advice here, please.
I am currently developing an iRule which will in the end send user requests to different pools based on IP addr, user agents, an exist...
hoolio
Cirrostratus
Nov 07, 2007Hi Patrick,
Sorry, I didn't realize that HTTP::query only allows you to get the query string value, and not set it. HTTP::uri will allow you to get or set the URI, including the query string.
If you know there will never be a pre-existing query string in the original client request, you could just append the updated URI to the existing URI. However, I expect there would be requests with existing query strings for most apps. To handle that, you could use string map to replace the query string with the new query string within the entire URI. Here is an example:
...
original query string is returned by [HTTP::query]
check if query string is empty
if {[string length [HTTP::query]] > 0}{
query string wasn't empty, so we have to preserve what was there
make a change to the query string
set updated_qs "[HTTP::query]&someparameter=somevalue"
update the URI by replacing the old query string with the new
HTTP::uri [string map "[HTTP::query] $updated_qs" [HTTP::uri]]
} else {
query string wasn't set, so we can just append to the existing URI
HTTP::uri "[HTTP::uri]?someparameter=somevalue"
}
...
You won't be able to log the change to the URI using HTTP::uri, as the value is cached. But you could log the string map output to see the change:
log local0. "Updated URI: [string map \"[HTTP::query] $updated_qs\" [HTTP::uri]]"
Aaron
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