Forum Discussion
Reroute traffic based on request content
Most certainly. But you may have to consider other factors. Is this a single atomic request, or will the user make multiple requests? Will all of the user requests contain the information you're looking for?
Let's assume for a moment that these are atomic requests, and by "VIP" you actually mean servers, or a pool of servers. You could simply use a string function to parse out the content you're looking for and make a load balancing decision based on that. Something like this:
when HTTP_REQUEST {
if { [HTTP::header exists Content-Length] } {
Collect the payload and trigger the HTTP_REQUEST_DATA event
HTTP::collect [HTTP::header Content-Length]
}
}
when HTTP_REQUEST_DATA {
The HTTP request payload is buffered and accessible here
Now use string functions to get the username from the request payload
set username [findstr [HTTP::payload] "" 10 ""]
switch $username {
"bob" { pool bob_pool }
"alice" { pool alice_pool }
"eve" { pool eve_pool }
"oscar" { pool oscar_pool }
default { pool default_pool }
}
}
Of course this is a wildly simplistic example, and you could a) use XML_CONTENT_BASED_ROUTING to parse the XML payload with real xpath processing, and b) use something more elaborate than a static switch statement to test usernames. In any case, the findstr command is a fast and easy way to selectively extract information from a string, in this case the data between "" and "".
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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