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...
skunk69_85565
Nov 07, 2007Historic F5 Account
Aaron,
you pointed me in the right way, and finally I got it working :-). Sure this is not the best way, but it seams to work - not tested with customer right now.
At the moment I am not sure how I can fulfill the requirement of setting the query parameter with the value of the cookie (e.g. &AB_test=A-3)? This is needed for analytics. Any idea here?
For your info: I have a VS with no default pool, no persistence profile, just this irule:
when RULE_INIT {
Value defines how many new requests will end up at siteA "
set ::DefaultPerc 30
Global Test ID which will manually changed "
set ::TestID 7
Reset of sample_id
set ::sample_id 0
}
look for bad ip addr and send straight to poolA
when CLIENT_ACCEPTED {
if { [matchclass [IP::remote_addr] equals $::BlackList] } {
log local0. "Client IP is [IP::remote_addr] and send to site A"
pool poolA
}
log local0. "Client IP is [IP::remote_addr]"
}
when HTTP_REQUEST {
set UA [HTTP::header User-Agent]
log local0. "User Agent is $UA "
look if user agent is a crawler and send straight to poolA
if { [matchclass [string tolower $UA] contains $::SearchEngineCrawler] } {
log local0. "Crawler found: $UA and send to site A"
pool poolA
return
}
elseif { [HTTP::cookie exists "AB_test"] } {
not a bad ip addr and no crawler, look for existing cookie
set client_id [HTTP::cookie "AB_test"]
this is used to direct the traffic
set qstring [HTTP::query]
log local0. "Cookie found= $client_id"
log local0. "old query string= $qstring "
set qstring $client_id
log local0. "new query string= $qstring "
now the load balancing is done
if { $qstring starts_with "A"} {
pool poolA
log local0. "send to poolA"
return
}
elseif { $qstring starts_with "B"} {
pool poolB
log local0. "send to poolB"
return
}
}
else {
no bad ip, no crawler and no cookie set or new request
log local0. "no cookie need to sample!"
set id [expr { int(100 * rand()) }]
log local0. "id ist $id"
this is where the decision is made where to send traffic to
if {$id <= $::DefaultPerc } {
set ::sample_id A-$::TestID
}
else {
set ::sample_id B-$::TestID
}
log local0. "sample id is= $::sample_id "
set qstring [HTTP::query]
log local0. "old query string= $qstring "
set qstring $::sample_id
log local0. "new query string= $qstring "
loadbalance new requests
if { $qstring starts_with "A"} {
pool poolA
log local0. "send to poolA "
return
}
elseif { $qstring starts_with "B"} {
pool poolB
log local0. "send to poolB "
return
}
}
log local0. "END"
}
when HTTP_RESPONSE {
HTTP::cookie insert name AB_test value $::sample_id
}
Any idea how to get the query parameter set is welcome.
Thanks for your help so far.
Patrick
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