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 existing cookie or on a customized percentage value.
Ok, I have an idea but struggle with the following:
This is the part where I look for the cookie, if present I want to insert it into the HTTPquery or as a part of the HTTP::uri.
elseif { [HTTP::cookie exists "AB_test"] } {
set client_id [HTTP::cookie "AB_test"]
set old_uri [HTTP::uri]
set qstring [HTTP::query]
log local0. "Cookie found= $client_id"
log local0. "old URI= $old_uri "
log local0. "old query string= $qstring "
set qstring $client_id
log local0. "new query string= $qstring "
HTTP::query "$qstring"
log local0. "new query= [HTTP::query]"
}
if { [HTTP::query] starts_with "/A"} {
pool poolA
return
}
elseif { [HTTP::query] starts_with "/B"} {
pool poolB
return
}
Not sure what I am doing wrong here, but the new HTTP:query is empty.....
Any help is appreciated.
Patrick
- hoolio
Cirrostratus
I think the value retrieved using HTTP::query and HTTP::uri is cached for performance reasons. So even if you set it to a new value, the command will still return the original value. - skunk69_85565Historic F5 AccountHi Aaron,
- hoolio
Cirrostratus
You're setting qstring to the value of [HTTP::query] in an else block, but I would guess that block isn't always being hit. So you get an error when trying to reference $qstring when it hasn't been set. You could either set it to some default value or check that it has been set before trying to use it. Here's an example of the latter using 'info exists' (Click here๐... if { [info exists qstring] && $qstring starts_with "/A"} { pool poolA } elseif { [info exists qstring] && $qstring starts_with "/B"} { pool poolB } else { pool default_pool }
- skunk69_85565Historic F5 AccountAaron,
- hoolio
Cirrostratus
If you're setting the pool, you will need to get the user back to the same pool in your rule in order for persistence based on the pool members to work. Based on what you've posted so far, I assume the AB_test cookie will be sent in all requests.if { $qstring starts_with "A"} { pool poolA persist cookie insert poolA_cookie_persist log local0. "send to poolA" return } elseif { $qstring starts_with "B"} { pool poolB persist cookie insert poolB_cookie_persist log local0. "send to poolB" return }
- skunk69_85565Historic F5 AccountAaron,
- hoolio
Cirrostratus
Hi Patrick,... 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" } ...
log local0. "Updated URI: [string map \"[HTTP::query] $updated_qs\" [HTTP::uri]]"
- skunk69_85565Historic F5 AccountAaron,
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