Jonathan_Scholi
Mar 19, 2012Cirrostratus
Direct traffic based on POST result
I got a request to send traffic to one of two servers based on the the contents of a POST request. Specifically, if a certain reference parameter in the POST is even, one server takes the traffic, and if the reference parameter is odd, the other server takes the traffic. The Tcl modulo operation works as expected, as determined by looking at the logs, but the correct server is not selected. The rule is like this:
when HTTP_REQUEST {
HTTP::version "1.0"
if {[active_members mysite.com] > 1}{
if { [HTTP::header exists "Content-Length"] && [HTTP::header "Content-Length"] 0 } {
HTTP::collect $content_length
}
}
}
when HTTP_REQUEST_DATA {
if {[active_members mysite.com] > 1}{
set payload [HTTP::payload]
set reference ""
regexp {reference=([0-9]+)} $payload blank reference
if {$reference % 2 == 0}
{
pool mysite.com member 10.11.12.13 443
log local0. "Reference ends with even"
log local0. "[LB::server]"
}
elseif {$reference % 2 == 1}
{
pool mysite.com member 10.11.12.14 443
log local0. "Reference ends with odd"
log local0. "[LB::server]"
}
HTTP::release
}
}
The logs show the expected "Reference ends with even/odd", but the server persists in using the wrong server half the time. Persistence is not enabled. Is there a better approach I could be taking here?